candoimage / frctl_twig
Twig extension to integrate seamlessly with fractal twig adapter
Installs: 2 255
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 7
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
- twig/twig: ^1.14|^2.0
Suggests
- symfony/framework-bundle: The framework bundle to integrate the extension into Symfony
- symfony/twig-bundle: The twig bundle to integrate the extension into Symfony
This package is auto-updated.
Last update: 2025-03-24 19:07:52 UTC
README
The FrctlTwigExtension component allows you set seamlessly integrate your Fractal twig templates.
Installation
To install the latest stable version of this component, open a console and execute the following command:
$ composer require candoimage/frctl_twig
Usage
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.
License
This component is under the MIT license. See the complete license in the LICENSE file.
Reporting an issue or a feature request
Issues and feature requests are tracked in the Github issue tracker.
Author Information
If you find this component useful, please add a ★ in the GitHub repository page.