amteich / kirby-twig

Twig templating support for Kirby CMS
MIT License
48 stars 12 forks source link

Overwriting a default block snippet from inside a plugin does not render the Twig code #23

Closed renestalder closed 3 years ago

renestalder commented 3 years ago

I have everything specific to a website in a plugin, including templates, blueprints, controllers. This also works fine with the Twig plugin. I can reference "templates" in my plugin to Twig files instead of PHP.

I noticed, this doesn't seem to work for snippets.

When I try to overwrite the heading block (because my plugin extends the fields via a blueprint), the template content will render as raw output, not rendered by the Twig engine.

Kirby::plugin('website/kirby-plugin', [
'snippets' => [
        'blocks/heading' => __DIR__ . '/snippets/blocks/heading.twig'
    ],
]}

The heading overwrite might look something like this:

{% import '@ui/components/heading/macros.twig' as heading %}

{{ heading.render(block) }}

For all other parts so far, the Twig engine seems to rendered everything properly, just not for those snippets defined in the plugin.

As an example, this works fine:

    'templates' => [
        'default' => __DIR__ . '/templates/default.twig',
        'blog-post' => __DIR__ . '/templates/blog-post.twig',
    ],

It most likely doesn't necessarily have something to do with the fact that this is all defined in a plugin. Entirely possible, this also happens when overwriting default blocks outside a plugin.

renestalder commented 3 years ago

A short check whether this has something to do with the plugin or not reveals, that when I move the blocks/heading.twig from the plugin to the kirby instance directly, it renders the Twig content to HTML.

So, it looks like it has something to do with assigning snippets in plugins.

seehat commented 3 years ago

Hi @renestalder, thank you for pointing this out. I fixed this in the newest release 4.1.4. Does it work now?

renestalder commented 3 years ago

@seehat Wow, that was fast. Are you a magician or something? It works like a charm.

Thank you a million times.

seehat commented 3 years ago

Thank you! I'm happy that it works like a charm now. I appreciate you for writing your last message, especially the magician part. :)