Bamboo Twig. Drupal 8 powered module.
Bamboo Twig module provides some Twig extensions with some useful functions and filters that can improve development experience.
You need Bamboo Twig if
- You need to "Format date using Drupal I118n" from your twig.
- You need to "Load a Block" from your twig.
- You need to "Load an Entity with view mode" from your twig.
- You need to "Load a Form" from your twig.
- You need to "Load a ImageStyle" from your twig.
- You need to "Retrieve the Extension file from given mimeType" from your twig.
Bamboo Twig can do a lot more than that, but those are some of the obvious uses of Bamboo Twig.
Performances
For performances reasons, Bamboo Twig has been splitted in multiple sub-modules for each topics he provides Twigs.
Bamboo Twig versions
Bamboo Twig is only available for Drupal 8 !
The module is ready to be used in Drupal 8, there are no known issues.
Dependencies
The Drupal 8 version of Bamboo Twig requires Disrupt Tools if you use Bamboo Twig - Images.
Similar modules
For now (2017-03-21) Twig Tweak is a far better option than Bamboo Twig.
- Clean away twig debugging output Twig Clean Up.
- Define and expose self-contained UI patterns UI Patterns.
- Provides the raulfraile/ladybug Dumper Devel Ladybug.
- Add attributes to link() item.url's Twig Link Attributes.
- Reuse small self contained parts of their theme templates Partial.
- Allows to embed views TVE.
- Porting Twig extensions to Drupal Twig Extensions.
- Set of tools to debug Drupal LGP.
- Set of tools to deal with render arrays Twig Renderable.
- Get partial data from field render arrays Twig Field Value.
- This module allows you to execute PHP code from Twig - Do not use this module - Twig PHP.
Roadmap
8.1.x
- UnitTests
- Twig Extensions (Dates, Texts, Array)
- Loader for Views
- Loader for Regions
- Loader for Field
- Loader for Menu
- Usage of Token
8.2.x
- Improvments on ImageStyle between pregenerated derivated or on-the-fly generation
Supporting organizations
This project is sponsored by Antistatique. We are a Swiss Web Agency, Visit us at www.antistatique.net or Contact us.
Examples
Dates
{# Format date using Drupal i118n. #}
<dt>Format date:</dt>
<dd>{{ node.changed.value|date_format('d M, h:i A') }}</dd>
Files
{# Retrieve file Url into theme. #}
<dt>Files:</dt>
<dd>{{ theme_url('bartik', 'images/required.svg') }}</dd>
{# Retrieve the Extension file from given mimeType. #}
<dt>Extension file:</dt>
<dd>{{ file.entity.mimeType|extension_guesser() }}</dd>
Loaders
{# Load a Block. #}
<dt>Block:</dt>
<dd>{{ load_block('bartik_powered') }}</dd>
{# Load an Entity. #}
<dt>Entity:</dt>
<dd>{{ load_entity('node', node.nid.value) }}</dd>
{# Load an Entity with view mode. #}
<dt>Entity:</dt>
<dd>{{ load_entity('node', node.nid.value, 'teaser') }}</dd>
{# Load a Form. #}
<dt>Form:</dt>
<dd>{{ load_form('contact', 'ContactForm') }}</dd>
Image Styles
{# Image Style from File ID. #}
<dt>Image Styles:</dt>
<dd>{% set images = image_style_field(node.field_image, {'thumb': 'thumbnail', 'lg': 'large'}) %}</dd>
{# Image Style from Field. #}
<dt>Image Styles:</dt>
<dd>{% set images = image_style_file(node.field_image.entity.fid.value, {'thumb': 'thumbnail', 'lg': 'large'}) %}</dd>
Configurations
{# Configuration from Config API. #}
<dt>Config API:</dt>
<dd>{% set settings = load_config('system.site') %}</dd>
{# Configuration from State API. #}
<dt>State API:</dt>
<dd>{% set settings = load_state('system.cron_last') %}</dd>
Comments
Comment #2
wengerk