sunlight-cms/twig-plugin

Twig integration plugin

v1.0.2 2023-12-16 13:56 UTC

This package is auto-updated.

Last update: 2024-11-30 02:33:40 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 for call_user_func()
  • dump([value], [maxLevel], [maxStringLen]): alias for Kuria\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 of Twig\Environment
  • loader - instance of SunlightExtend\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.