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

Documentation: twig.function.* option #17

Closed fvsch closed 7 years ago

fvsch commented 7 years ago

Document the new way to expose a function in the templating environment:

c::set('twig.function.myFunction', 'myFunctionsFullName');
c::set('twig.function.myFunction', function(){ /* return something */ });

And similarly for filters.

The old way, c::set('twig.env.functions', ['myFunctionsFullName']);, still works.

This feature enables plugins to register Twig functions and namespaces:

c::set([
  'twig.function.doSomething' => 'MyPlugin::doSomething',
  'twig.namespace.myplugin'   => __DIR__ . '/templates'
]);