twig tutorial - Change the content in Twig - twig php - twig template



Change the content of an included template

article.twig.html

<article>
    <h1>{{ article.title }}</h1>
    {% block content %}
    <p>{{ article.content }}</p>
    {% endblock %}
</article>

articles.twig.html

{# use default template for article #}
{% for article in articles %}
    {% include "article.twig.html" %}
{% endfor %}
{# use custom template for article #}
{% for article in articles %}
    {% embed "article.twig.html" %}
        {% block content %}
            <img src="{{ article.image }}" alt="{{ article.title }}" />
            {{ parent() }}
        {% endblock %}
    {% endembed %}
{% endfor %}

Related Searches to twig tutorial - Change the content in Twig