The FrctlTwigExtension component allows you set seamlessly integrate your Fractal twig templates.
To install the latest stable version of this component, open a console and execute the following command:
$ composer require candoimage/frctl_twig
The first step is to register the extension in the twig environment
services:
Frctl\Twig\Extension\FrctlTwigExtension:
tags:
- { name: twig.extension }
or manually in your code
/* @var $twig Twig_Environment */
$twig->addExtension(new Frctl\Twig\Extension\FrctlTwigExtension());
Then you need to configure the new include namespace the fractal templates:
twig:
paths:
'%kernel.project_dir%/../frontend/src/components': FrctlTwig
or manually in your code
$loader->addPath(dirname(__DIR__) . '/../frontend/src/components', 'FrctlTwig');
Once registered, you can use the new render
tag seamlessly in your twig templates:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
</head>
<body>
{% render "@component" with {some: 'values'} %}
</body>
</html>
Advanced examples:
{# @component will have access to the variables from the current context and the additional ones provided #}
{% render'@component' with {'foo': 'bar'} %}
{# only the foo variable will be accessible #}
{% render'@component' with {'foo': 'bar'} only %}
{# @component will have access to the variables from the current context and the additional ones provided and the ones provided in the fractal yml config #}
{% render'@component' with {'foo': 'bar'} merge frctl context %}
{# only the foo variable and the ones provided in the fractal yml config will be accessible #}
{% render'@component' with {'foo': 'bar'} only merge frctl context %}
The variable variant
contains the selected variant.
This component is under the MIT license. See the complete license in the LICENSE file.
Issues and feature requests are tracked in the Github issue tracker.
If you find this component useful, please add a ★ in the GitHub repository page.