amteich / kirby-twig

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

Is it possible to include snippets of a php library in a twig file? #13

Closed NiklasBuchfink closed 4 years ago

NiklasBuchfink commented 4 years ago

Hey, first of all, high praise for the helpful plugin :) I tried to implement the kirby podcaster plugin (https://github.com/mauricerenck/kirby-podcaster) in a project. For the most part, it works fine, but errors have occurred when using twigs include statement with a PHP snippet. Even with the creation of a new namespace, a successful implementation was not possible.

Is there a better way to access the PHP snippets via Twig? Or is it necessary to re-code this part in the branch?

seehat commented 4 years ago

Hey, can you give me a simple codeexample of what you want to achieve?

NiklasBuchfink commented 4 years ago

The documentation of the plugin recommends the following:

If you want an audio player appear on your episode page, just add the follow snippet to your template: <?php snippet('podcaster-player'); ?>

So I tried to add the snippet to my template with: {% include '@plugins/podcaster/snippets/podcaster-player.php' %}

Then a part of the php code is printed on the website without errors in the console: siblings()->find('feed'); switch($podcast->playerType()) { case 'podlove': snippet('podcaster-podlove-player', ['page' => $page, 'podcast' => $podcast]); break; case 'html5': snippet('podcaster-html5-player', ['page' => $page, 'podcast' => $podcast]); break; } ?>

seehat commented 4 years ago

Please try the following:

{% snippet('podcaster-player.php'); %}

NiklasBuchfink commented 4 years ago

When I add the command to my page an Twig\Error\SyntaxError occurs: Unexpected character ";".

And without the ";" : Unknown "snippet" tag.

seehat commented 4 years ago

Sry Niklas, this was my fault, try:

{{ snippet('podcaster-player') }}

NiklasBuchfink commented 4 years ago

Thank you Christian, this works :)

seehat commented 4 years ago

You are welcome. :)