Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devtronic/twig-compose
A twig extension to compose templates from multiple child templates.
https://github.com/devtronic/twig-compose
multi-extend php symfony twig twig-extension
Last synced: 18 days ago
JSON representation
A twig extension to compose templates from multiple child templates.
- Host: GitHub
- URL: https://github.com/devtronic/twig-compose
- Owner: devtronic
- License: mit
- Created: 2018-01-17T19:53:53.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-21T04:17:00.000Z (about 5 years ago)
- Last Synced: 2024-11-24T16:22:38.852Z (about 2 months ago)
- Topics: multi-extend, php, symfony, twig, twig-extension
- Language: PHP
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ✨ Twig Compose Environment ✨
A twig extension to compose templates from multiple child templates.## ❓ What does this?
For example you've a base template and N child template which can modify the base Template.
If the templates are fixed, there is no problem you can extend from each other.
Is the number of templates dynamic you can't use extend. In that case you can use this bundle.
Simply call the compose method, pass a base template and a array of sub-templates... and wibbly wobbly you've a template
which contains every content of every child template 🌠## 📦 Installation
```bash
$ composer require devtronic/twig-compose
```## ❤ Sponsors
No sponsors at the moment. [Become a sponsor](https://github.com/sponsors/devtronic)## 🛠 Usage
For details take a look in the tests directory
### ➡ With a your existing Twig_Environment
```php
addExtension(new Devtronic\TwigCompose\ComposeExtension());
$template = ComposeEnvironment::composeStatic($twig, 'base.html.twig', ['pluginA.html.twig', 'pluginB.html.twig']);echo $template->render([]);
```### ➡ With the ComposeEnvironment
```php
compose('base.html.twig', ['pluginA.html.twig', 'pluginB.html.twig']);echo $template->render([]);
```### ➡ Auto composing templates (Experimental & ComposeEnvironment only)
```php
addPath('/res/theme1', 'Theme1');
$loader->addPath('/res/theme2', 'Theme2');// If autocompose is enabled, all registered paths will be checked.
// If a file with the the same name (e.g. base.html.twig) exists,
// it will be loaded & composed with the `base.html.twig` inside the main-theme folder
$twig->setAutoCompose(true);
$template = $twig->load('base.html.twig');echo $template->render([]);
```