Skip to content

Instantly share code, notes, and snippets.

@ubermuda
Created August 12, 2014 16:16
Show Gist options
  • Save ubermuda/305f9cc71b80931eee65 to your computer and use it in GitHub Desktop.
Save ubermuda/305f9cc71b80931eee65 to your computer and use it in GitHub Desktop.
I was looking for a way to do this, turns out twig has exactly this feature! http://twig.sensiolabs.org/doc/tags/embed.html
{# hypothetic twig tag "with" #}
{% with 'panel.html.twig' %}
{% block panel_title %}This is the panel title{% endblock %}
{% block panel_body%}
<p>This is the panel body</p>
{% endblock %}
{% endwith %}
{% with 'panel.html.twig' %}
{% block panel_title %}This is another panel title{% endblock %}
{% block panel_body%}
<p>And the body</p>
{% endblock %}
{% endwith %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{% block panel_title %}{% endblock %}</h3>
</div>
<div class="panel-body">
{% block panel_body %}{% endblock %}
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment