Lines Matching refs:Twig

1 Extending Twig
6 This section describes how to extends Twig for versions **older than
10 Twig can be extended in many ways; you can add extra tags, filters, tests,
16 The first section of this chapter describes how to extend Twig easily. If
23 When extending Twig by calling methods on the Twig environment instance,
24 Twig won't be able to recompile your templates when the PHP code is
29 Before extending Twig, you must understand the differences between all the
32 First, remember that Twig has two main language constructs:
38 To understand why Twig exposes so many extension points, let's see how to
60 the most complex extension point of Twig.
98 Keep in mind the following when you want to extend Twig:
118 $twig = new \Twig\Environment($loader);
141 When compiling this template to PHP, Twig looks for the PHP callable
142 associated with the ``lower`` filter. The ``lower`` filter is a built-in Twig
174 {{ "Twig"|rot13 }}
179 ``\Twig\Environment`` instance::
181 $twig = new \Twig\Environment($loader);
193 {{ "Twig"|rot13('prefix_') }}
232 Twig will then pass the current environment as the first argument to the
235 function twig_compute_rot13(\Twig\Environment $env, $string)
264 Dynamic filters support was added in Twig 1.5.
304 When compiling this template to PHP, Twig looks for the PHP callable
305 associated with the ``constant`` function. The ``constant`` function is a built-in Twig
314 ``addFunction()`` method on the ``\Twig\Environment`` instance::
316 $twig = new \Twig\Environment($loader);
321 // $this is an object that implements \Twig\Extension\ExtensionInterface.
322 $twig = new \Twig\Environment($loader);
331 Dynamic functions support was added in Twig 1.5.
364 One of the most exciting feature of a template engine like Twig is the
366 feature as you need to understand how Twig's internals work.
398 ``\Twig\Environment`` instance::
400 $twig = new \Twig\Environment($loader);
408 class Project_Set_TokenParser extends \Twig\TokenParser\AbstractTokenParser
410 public function parse(\Twig\Token $token)
413 $name = $this->parser->getStream()->expect(\Twig\Token::NAME_TYPE)->getValue();
414 $this->parser->getStream()->expect(\Twig\Token::OPERATOR_TYPE, '=');
417 $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
431 tag. It should return a ``\Twig\Node\Node`` instance that represents the node (the
464 class Project_Set_Node extends \Twig\Node\Node
466 …public function __construct($name, \Twig\Node\Expression\AbstractExpression $value, $lineno, $tag …
471 public function compile(\Twig\Compiler $compiler)
495 ``\Twig\Node\ForNode`` for a usage example).
500 * ``indent()``: Indents the generated code (see ``\Twig\Node\BlockNode`` for a
503 * ``outdent()``: Outdents the generated code (see ``\Twig\Node\BlockNode`` for a
521 to host all the specific tags and filters you want to add to Twig.
525 When packaging your code into an extension, Twig is smart enough to
531 Before writing your own extensions, have a look at the Twig official
532 extension repository: https://github.com/twigphp/Twig-extensions.
543 function initRuntime(\Twig\Environment $environment);
555 * @return \Twig\NodeVisitor\NodeVisitorInterface[]
562 * @return \Twig\TwigFilter[]
569 * @return \Twig\TwigTest[]
576 * @return \Twig\TwigFunction[]
603 ``\Twig\Extension\AbstractExtension`` class instead of implementing the whole interface. That
605 ``\Twig\Extension\AbstractExtension`` provides empty implementations for all other methods.
612 class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
625 Twig does not care where you save your extension on the filesystem, as all
631 $twig = new \Twig\Environment($loader);
647 class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
665 class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
681 method. This method must return an array of filters to add to the Twig
684 class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
708 class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
740 class MyCoreExtension extends \Twig\Extension\AbstractExtension
765 $twig = new \Twig\Environment($loader);
773 to the Twig environment::
775 class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
795 class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
801 '!' => ['precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'],
804 …'||' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' =…
805 …'&&' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' …
818 class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
834 Support for functional tests was added in Twig 1.10.
856 class Project_Tests_IntegrationTest extends \Twig\Test\IntegrationTestCase
872 Fixtures examples can be found within the Twig repository
873 `tests/Twig/Fixtures`_ directory.
879 ``\Twig\Test\NodeTestCase``. Examples can be found in the Twig repository
880 `tests/Twig/Node`_ directory.
884 .. _`tests/Twig/Fixtures`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Fixtures
885 .. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Node