Drupal 8 includes part template

I am trying to use Drupal 8 with my own theme, due to the large structural differences for my requirements. I have a page - front.twig.html and page.twig.html, I would like to create parts of the template as used in phrozn oder in a regular Symfony2 project, for example, footer.html.twig and header.html.twig. These templates are stored in the / parts / subdirectory

But wenn I call these templates normal, I just get a string with the name of the template.

For instance:

{# in page.html.twig or page--front.html.twig #}
{% include 'parts/footer.html.twig' %} 

Returns the file name as a string:

parts/footer.html.twig

Can this be done with Drupal 8?

+4
source share
3 answers

it is possible to use the template name in the path

{% include '@mytheme/parts/footer.html.twig' %}

https://drupal.stackexchange.com/questions/141066/drupal-8-include-part-template

+3

,

{% include directory ~ '/parts/footer.html.twig' %}

{% include '@mytheme/parts/footer.html.twig' %}

, .

{# filename: page-layout.html.twig #}

{% block content%}
{{ page.content }}
{% endblock%}

{% block footer%}
{% include '@mytheme/parts/footer.html.twig' %}
{% endblock%}

, -

{# filename: page--front.html.twig #}
{% block footer%}
<div> I want to handle a different footer in here</div>
{% endblock%}

, , , Drupal.

.

+3

Now that you have https://www.drupal.org/node/2291449 , you can also do:

{% include 'footer.html.twig' %}
+1
source

All Articles