gglnx / twig-component-handle-loader
Load Twig templates using Fractal-style component handles
Installs: 4 233
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.2.5
- twig/twig: ^3.0
Requires (Dev)
README
Twig loader for loading templates by using a component handle based on the Fractal naming convention.
For example:
├── components
│ └── small-components
| └── button
| └── button.twig # Will be @button
You can now include the button template with the @[component-handle]
syntax:
{% include '@button' %}
Requirements
- Twig >=2.14
- PHP >=7.4
Installation
The recommended way to install this loader is via Composer:
composer require gglnx/twig-component-handle-loader
Then you can use this loader directly with Twig:
require_once '/path/to/vendor/autoload.php'; $loader = new \Gglnx\TwigComponentHandleLoader\Loader\ComponentHandleLoader('../path-to-my-components'); $twig = new \Twig\Environment($loader);
You can also combine this loader with other loaders using ChainLoader
.
Differences between this loader and the Fractal implementation
- Ordering and hiding are yet not fully supported and tested.
- Using Prefixes is not possible.
- Overriding handle in the component configuration is not possible.
Prefixing and overriding the component handle require to read the corresponding component configuration. This could be out-of-scope for this loader and maybe better placed in a specific Twig Fractal loader.