Inline template with Drupal 8 and Twig | Drupal 8

Inline template with Drupal 8 and Twig

Submitted by editor on Sat, 06/04/2016 - 12:15
Question

How to use the inline templating system (inline_template) of drupal 8 render array with a inline twig template ?

Example 1. Basic inline template

    $output[] = array(
      '#type' => 'inline_template',
      '#template' => '{{ yourvar }}',
      '#context' => array(
        'yourvar' => 'The Value',
      ),
    );
    return $output;

Example 2. Display a basic value and a raw HTML

    $output[] = array(
      '#type' => 'inline_template',
      '#template' => '{{ yourvar }} {{ yourhtml | raw }}',
      '#context' => array(
        'yourvar' => 'Your Var',
        'yourhtml' => '<span style="color:red;">Your HTML</span>',
      ),
    );
    return $output;

Add new comment