sunlight-cms / twig-plugin
Twig integration plugin
v1.0.2
2023-12-16 13:56 UTC
Requires
- twig/twig: ^3.3.7
This package is auto-updated.
Last update: 2024-10-30 02:16:27 UTC
README
Twig integration plugin.
Contents
Requirements
- PHP 7.2.5+
- SunLight CMS 8
Usage
See Twig documentation.
<?php use SunlightExtend\Twig\TwigBridge; $output = TwigBridge::render('@extend/my-plugin/example.html.twig', [ 'foo' => 'bar', ]);
HCM module
Any extra arguments after template name are available in the args
variable.
[hcm]twig,upload/my_template.html.twig,foo,bar[/hcm]
Namespaces
- default: project root
@extend
: plugins/extend@templates
: plugin/templates
Globals
The sl
global variable is available to all templates.
Proxies allow calling any static method on the target class.
Functions
lang()
: alias for_lang()
call()
: alias forcall_user_func()
dump([value], [maxLevel], [maxStringLen])
: alias forKuria\Debug\Dumper::dump()
Extend events
twig.init
Called when Twig is being initialized. Can be used by other plugins to register their custom twig functionality.
Arguments:
env
- instance ofTwig\Environment
loader
- instance ofSunlightExtend\Twig\TemplateLoader
Overriding templates
Templates may be overriden by calling $loader->override($name, $newName)
during the twig.init event.
To bypass template overrides (e.g. when extending overriden templates),
prepend !
to the template name. Example: !@extend/my-plugin/example.html.twig
.