Post

Twig Include Embed and Extends

Twig Include

  • Returns the rendered content You can pass in simple key value pairs to use within your include.
1
2
3
4
5
6
{%
include '@theme_name/component/component.twig' with
   {
     key: value,
   } only
%}

Twig Embed

  • Same as includes yet they allow for the use of twig blocks
  • Blocks are used for inheritance and act as a placeholder and inheritance at the same time.
  • Twig blocks are not the same as drupal blocks
1
2
3
4
5
6
7
8
9
{%
embed '@theme_name/component/component.twig' with
   {
     key: value,
   } only
%}
{% block content %}
<p> Content can go here. </p>
{% endblock %}

Twig Extends

  • allows you to include the content of another component and replace it with blocks
1
2
3
4
5
{%
extends '@theme_name/component/component.twig' with
   {% block content %}
      <p> Some child content goes here. </p>
   {% endblock %}
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.