Answers.Body: <p>If <code>partial_with_form.twig</code> isn’t making any of its own customizations to <code>form.twig</code>, then I’d just include the <code>form.twig</code> template using an <code>{% include %}</code> tag, and wrap that whole thing with a <code>{% block %}</code>, so if a template wants to include the partial <em>and</em> make changes to the form, they can just redefine the form themselves.</p>
  
  <p><strong>partial_with_form.twig:</strong></p>
  
  <pre><code>{% block form %}
    {% include 'form' %}
  {% endblock %}
  </code></pre>
  
  <p><strong>Other template:</strong></p>
  
  <pre><code>{% embed `partial_with_form` %}
    {% block form %}
      {% embed 'form' %}
        {% block form_extension %}
          &lt;!-- ... --&gt;
        {% endblock %}
      {% endembed %}
    {% endblock %}
  {% endembed %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-21T13:14:23.693Z
Answers.Text: Yeah, that crossed my mind later on as well, maybe that is actually easier in the long term and less confusing.
Answers.UserDisplayName: jishi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-21T12:51:10.493Z
Answers.LastActivityDate: 2020-02-21T12:51:10.493Z
Answers.UserDisplayName: Brandon Kelly
Answers.Body: <p>Hm, seems like you can use block() but it can't be within the embed block. Putting it in a variable first and use that variable in the embed block works.</p>
  
  <pre><code>{% set petition_after_fields_block = block('petition_after_fields') is defined ? block('petition_after_fields') %}
  {% embed 'form' %}
      {% block petition_after_fields %}
          {{ petition_after_fields_block|raw }}
          {# {{ block('petition_after_fields') }} -- This doesn't work, nor using a different block name #}
      {% endblock %}
  {% endembed %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-21T11:52:59.593Z
Answers.LastActivityDate: 2020-02-21T11:52:59.593Z
Answers.UserDisplayName: jishi
Body: <p>I'm trying to achieve some modularity using embeds, but with the possiblity to extend/inject customizations from the including template. </p>
  
  <p>Consider the following scenario:</p>
  
  <p>Have a modular partial which contains a form, say <code>form.twig</code>
  I want the ability to add new form fields at the end of the form, but using the otherwise common form.twig, so I add a <code>{% block form_extension %}</code> in form.twig</p>
  
  <p>I have another page template, that includes/embed that partial, say <code>page.twig</code>. Now, this works, I just add a block when embedding, and it gets injected.</p>
  
  <p>But, I also have another modular partial, say <code>partial_with_form.twig</code>, that embeds <code>form.twig</code>. And I want to be able to define the <code>form_extension</code> block, when embedding <code>partial_with_form</code>. </p>
  
  <p>Is this even possible? I have tried with parent() and block(), but none of them can give me the content of the supplied block unless I specify the targeting block in partial_with_form. But then it will be outputted there...</p>
  
Tags: <blocks><embed>
Title: pass block into embed and forward to another embed?
ThreadText: # pass block into embed and forward to another embed?
  
  (Asked by: username_0 on 2020-02-21)
  
  I'm trying to achieve some modularity using embeds, but with the possiblity to extend/inject customizations from the including template.
  
  Consider the following scenario:
  
  Have a modular partial which contains a form, say `form.twig`
  I want the ability to add new form fields at the end of the form, but using the otherwise common form.twig, so I add a `{% block form_extension %}` in form.twig
  
  I have another page template, that includes/embed that partial, say `page.twig`. Now, this works, I just add a block when embedding, and it gets injected.
  
  But, I also have another modular partial, say `partial_with_form.twig`, that embeds `form.twig`. And I want to be able to define the `form_extension` block, when embedding `partial_with_form`.
  
  Is this even possible? I have tried with parent() and block(), but none of them can give me the content of the supplied block unless I specify the targeting block in partial\_with\_form. But then it will be outputted there...
  
  **Tags:** blocks, embed
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-02-21. Score: 2 | Accepted answer
  
  If `partial_with_form.twig` isn’t making any of its own customizations to `form.twig`, then I’d just include the `form.twig` template using an `{% include %}` tag, and wrap that whole thing with a `{% block %}`, so if a template wants to include the partial *and* make changes to the form, they can just redefine the form themselves.
  
  **partial\_with\_form.twig:**
  
  ```
  {% block form %}
    {% include 'form' %}
  {% endblock %}
  
  ```
  
  **Other template:**
  
  ```
  {% embed `partial_with_form` %}
    {% block form %}
      {% embed 'form' %}
        {% block form_extension %}
          <!-- ... -->
        {% endblock %}
      {% endembed %}
    {% endblock %}
  {% endembed %}
  
  ```
  
  > **Comments:**
  > **username_0**: Yeah, that crossed my mind later on as well, maybe that is actually easier in the long term and less confusing.  
  
  ---
  
  ### Answer by username_0 on 2020-02-21. Score: 2
  
  Hm, seems like you can use block() but it can't be within the embed block. Putting it in a variable first and use that variable in the embed block works.
  
  ```
  {% set petition_after_fields_block = block('petition_after_fields') is defined ? block('petition_after_fields') %}
  {% embed 'form' %}
      {% block petition_after_fields %}
          {{ petition_after_fields_block|raw }}
          {# {{ block('petition_after_fields') }} -- This doesn't work, nor using a different block name #}
      {% endblock %}
  {% endembed %}
  
  ```
  
  
  ---
  
  