Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-15T23:02:52.913Z
Answers.Text: Is then maybe option to set variable inside included file so that it is accessible inside parent file?
Answers.UserDisplayName: saque tri
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-16T05:08:29.127Z
Answers.Text: That's not possible due to the scopes of Twig. You'll need a plugin for it or change the structure
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-15T22:40:08.410Z
Answers.LastActivityDate: 2018-08-15T22:40:08.410Z
Answers.UserDisplayName: Brandon Kelly
Body: <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>
  
Tags: <templating><seo><blocks>
Title: Nesting block tags doesnt work
ThreadText: # 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:
  
  ```
  <html>
  <head>
  {% block seo %}{% endblock %}
  </head>
  <body>
  {% block main %}{% endblock %}
  </body>
  </html>
  
  ```
  
  page.twig:
  
  ```
  {% extends 'layout.twig' %}
  
  {% block main %}
  
  some content..
  {% include 'pagination.twig' %}
  
  {% endblock %}
  
  ```
  
  pagination.twig:
  
  ```
  ... pagination links
  
  {% block seo %}
  <link href="url" rel="canonical">
  {% 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.
  
  ```twig
  {% extends 'layout.twig' %}
  
  {% block main %}
    some content..
    {% include 'pagination.twig' %}
  {% endblock %}
  
  {% block seo %}
    <link href="url" rel="canonical">
  {% 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  
  
  ---
  
  