<p>Unfortunately it’s not possible for an included template to override the contents of a block in the parent template, or its layout.</p>

<p>You’d need to just override the <code>seo</code> block from <code>page.twig</code> do whatever you need to do from there instead.</p>

<pre class="lang-twig prettyprint-override"><code>{% extends 'layout.twig' %}

{% block main %}
  some content..
  {% include 'pagination.twig' %}
{% endblock %}

{% block seo %}
  &lt;link href="url" rel="canonical"&gt;
{% endblock %}
</code></pre>

CC BY-SA 4.0
2018-08-15T23:02:52.913Z
Is then maybe option to set variable inside included file so that it is accessible inside parent file?
saque tri
CC BY-SA 4.0
2018-08-16T05:08:29.127Z
That's not possible due to the scopes of Twig. You'll need a plugin for it or change the structure
Robin Schambach
CC BY-SA 4.0
2018-08-15T22:40:08.410Z
2018-08-15T22:40:08.410Z
Brandon Kelly
<p>I have pagination twig component that needs to inject seo links into  of page (rel canonical).</p>

<p>I tried to use <code>{% block %}</code> twig tag for this, but problem is that pagination component is already included in another <code>{% block %}</code> tag containing main content of page.</p>

<p>In short, im trying to do this:</p>

<p>layout.twig:</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
{% block seo %}{% endblock %}
&lt;/head&gt;
&lt;body&gt;
{% block main %}{% endblock %}
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>page.twig:</p>

<pre><code>{% extends 'layout.twig' %}

{% block main %}

some content..
{% include 'pagination.twig' %}

{% endblock %}
</code></pre>

<p>pagination.twig:</p>

<pre><code>... pagination links

{% block seo %}
&lt;link href="url" rel="canonical"&gt;
{% endblock %}
</code></pre>

<p>When im using this code, block seo is empty. 
Can this be achived some other way?</p>

<templating><seo><blocks>
Nesting block tags doesnt work
# Nesting block tags doesnt work

(Asked by: username_0 on 2018-08-15)

I have pagination twig component that needs to inject seo links into  of page (rel canonical).
I tried to use {% block %} twig tag for this, but problem is that pagination component is already included in another {% block %} tag containing main content of page.
In short, im trying to do this:
layout.twig:


{% block seo %}{% endblock %}


{% block main %}{% endblock %}



page.twig:
{% extends 'layout.twig' %}

{% block main %}

some content..
{% include 'pagination.twig' %}

{% endblock %}

pagination.twig:
... pagination links

{% block seo %}

{% endblock %}

When im using this code, block seo is empty. 
Can this be achived some other way?

**Tags:** templating, seo, blocks


---

## 1 answers

### Answer by username_1 on 2018-08-15. Score: 2 | Accepted answer

Unfortunately it’s not possible for an included template to override the contents of a block in the parent template, or its layout.
You’d need to just override the seo block from page.twig do whatever you need to do from there instead.
{% extends 'layout.twig' %}

{% block main %}
  some content..
  {% include 'pagination.twig' %}
{% endblock %}

{% block seo %}
  
{% endblock %}

> **Comments:**
> **username_0**: Is then maybe option to set variable inside included file so that it is accessible inside parent file?  
> **username_2**: That's not possible due to the scopes of Twig. You'll need a plugin for it or change the structure  

---

