Twig Pre-Render
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Component created
Component changed
Component body
Twig Pre-render is a twig extension that allows you to pre-render and preprocess Drupal render arrays so you can get at all the contextual variables inside.
This is handy if you're trying to map Drupal elements to Drupal-independent Twig components. Have a paragraph that's supposed to be 1:1 with a component built by a non-Drupal developer? Just include the component twig into 'paragraph--myparagraph.html.twig' and call pre_render(field_myfield) to get access to all the variables inside of your field. Also includes a handy Image Attribute function that handles cleanly pulling variables from an image field.
You'll probably also want to use Component Libraries.
Things it currently does not do:
- Access checks
- Care about permissions
- Promise to emulate core in any way
But beyond that we've found it thoroughly useful in building component-based sites, especially if you use tools like KSS-Node and Pattern Lab.
If at some point core allows the ThemeManager::render() call to be split up, we'll probably want to refactor this module.
