Using snippets with Blade Plugin

So I’m trying out the Kirby 3 Blade template plugin by @beebmx and I’m wondering what the best way to us snippets is. I’m currently do something like this…

@foreach ($page->herobuilder()->toBuilderBlocks() as $block)
<?php snippet('blocks/' . $block->_key(), array('data' => $block)) ?>

But im guessing there is a ‘blade’ way to use the snippet? I thought sub-views might be it but it did not work.

Ah ha! Like the way from the old K2 plugin works…

{!! snippet('global/footer', ['scripts' => true]) !!}

You can still use the snippets like the old way:

{!! snippet('global/footer', ['scripts' => true]) !!}

But if you want to use the “blade” way you can use it with includes:

@include('', ['some' => 'data'])

Or you can create a component:

    <strong>Whoops!</strong> Something went wrong!

All the includes or components should be in the template directory with the .blade.php extension.

1 Like

Thanks @beebmx … thats the intended folder structure for using blade inside the snippets?

I renamed mine to .blade.php which means my snippet calls look like this now:

@if (!$page->showmenuinhero()->bool())
  {!! snippet('global/header.blade') !!}

Trouble is, I cant seem to be able to use Blade inside the snippets, it throws a whoops. I am also using the Builder plugin and to get it to load those blocks I had to do this…

@foreach ($page->herobuilder()->toBuilderBlocks() as $block)
  {!! snippet('blocks/' . $block->_key().'.blade', array('data' => $block)) !!}

But im guessing Blade wont work in those either. My files structure looks like this…

How can I use Blade inside snippets and work with the Builder Plugin?

ah… i see … i missed this line… some restructuring coming up then…

If you call the snippet helper, it will call the snippet directory.
If you call the @include blade directive the file has to be in the template directory.
For example:

<!-- /site/templates/blocks/basiccontent.blade.php -->


Or if you want to send data to the subview:

<!-- /site/templates/blocks/basiccontent.blade.php -->

@include('blocks.basiccontent', ['some' => 'data'])
1 Like