gaborottlik
gaborottlik

Reputation: 61

How to reuse block in an included template using twig

I have a userDashboard.html.twig template like this:

{% extends "AcmeDemoBundle::base.html.twig" %}

{% block content %}
    <h1>Name</h1>
{% endblock %}

{% include "AcmeDemoBundle::statistics.html.twig" %}

The controller call this template(userDashboard).

And a statistics.html.twig where I try to override or extend the content block:

{% extends "AcmeDemoBundle::userDashboard.html.twig" %}
    {% block content %}
       {{ parent() }}
       Something
    {% endblock %}

My problem is that I can't do this way. Can somebody recommend a solution?

Upvotes: 0

Views: 963

Answers (1)

kgilden
kgilden

Reputation: 10346

There's embed which basically lets you include templates while overriding some of their blocks:

{% embed "AcmeDemoBundle::userDashboard.html.twig" %}
    {% block content %}
       {{ parent() }}
       Something
    {% endblock %}
{% endembed %}

Upvotes: 1

Related Questions