fvsch / kirby-twig

Twig templating support for Kirby CMS 2. For Kirby 3, use https://github.com/amteich/kirby-twig
MIT License
70 stars 8 forks source link

Add support for custom filters #14

Closed jonathan-reisdorf closed 7 years ago

fvsch commented 7 years ago

Hi. Can you explain your use case? E.g. what are you trying to achieve on the template side?

In the 1.0 version of this plugin I used both functions and filters to expose Kirby’s helper functions, with a somewhat arbitrary separation (filters for transforming text, functions otherwise). Then I figured that it was difficult for users to remember if an helper was available as a function or filter, and switched to functions only.

Kirby developers are already used to two patterns in PHP templates:

<?php
// function
echo kirbytext($page->text());

// Field method
echo $page->text()->kirbytext();

Adding a third one seemed more confusing than helpful.

That being said, I don’t mind allowing users to expose functions as Twig filters if they want or need to. I’m just wondering what the original use case was.

Edit: eh, nevermind, it's a sensible improvement. Thanks for the PR!

jonathan-reisdorf commented 7 years ago

Hi, in our case the use case is that we have a separately maintained styleguide repo with patterns as twig files, which we now want to be able to include within the kirby website - and these external twig patterns also include filters. Besides that I totally agree with you that for just working with the kirby stuff functions are enough :) It's just that in this case it's an external repo we are including files from.