Add a TemplateFunctionProviderInterface
for better Framework integration
#69
Labels
Feature
A new feature to be added
Beside the
TemplateRendererInterface
a separate package is in mind for a total different usecase then the exist Renderer. It is targeting Framework authors which want to provide Framework functionality to different Template engines.Most PHP Frameworks provides for there Template engines some functions commonly is something like generate a URL based on a named Route. In most Template engines this kind of things are handled via
Extensions
like in Twig or Latte.There are currently some issues with a
TemplateFunctionProviderInterface
abstraction.A. Different implementation of TemplateFunction
The most common Template engines which does not have such implementation of Extension is
Blade
. Blade work the way that you can access allPHP
functions and methods as it is{{ any_method($part) }}
, as this is just PHP code which has advantages and disadvantages. Blade is by default used in Laravel which make a lot of usage ofGlobal Function
to provide helpers which are used in PHP Code but also in the Template itself. With this opens two questions.A1
should aTemplateFunctionProviderInterface
for Blade under Laravel just register Global Function.A2
should aTemplateFunctionProviderInterface
for Blade under different decorate Blade emulate global functions.A different way could be used that
TemplateFunctionProviderInterface
provides in Blade instead of functionsBlade directives
but as there usage is very different I'm not sure here. Other template engine like Spiral Stempler uses directives more often for things like route generation like here, so how this kind of mechanism should be implemented for this kind of engines is very complicated.B. Not all Template engines has extensions
This is also the part why it make sense that the whole
TemplateFunctionProviderInterface
is totally seperate from the Rendering of templates. Library and Framework authors should keep in mind that not all Template engines so they always should have the possibility todo the things already in the controller which is the way why the TemplateRendererInterface is also small and should be keep small. That way this Controller can not support only rendering the content via any template engine but also provide the data as JSON for any API based data receivers.Still from a Framework perspective a
TemplateFunctionProviderInterface
make sense so atleast a few engines can has full access to all available Template Functions of a FrameworkHow could a
TemplateFunctionProviderInterface
look like?As background of CMS where a lot of TwigExtension exist we did see a lot difference in performance how many Twig Extensions are registered. This means the
TemplateFunctionProviderInterface
should solve this issue that providing whichfunctions
are available does not required to initialize the Service. It is very common how in twig the twig.runtime works. A TemplateFunctionPRoviderInterface requires astatic
function this means the class don't need to initialized when it is checked what functions exist. Example:There will then be a
TwigExtension
for example which will be aBridge
to allTemplateFunctionProvider
and uses a PSR Container to access the service:The text was updated successfully, but these errors were encountered: