Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeating block in Twig

Tags:

twig

Is there anyway to repeat one block in twig like this:

<title>{% block title %}{% endblock %} | MyBusiness</title>

<meta name="title" content="{% block title %}{% endblock %} | MyBusiness"/>

In order to only declare the two blocks once? Like that:

{% block title %}   
The title I want to show in each title and metaTitle tags.{{ parent() }}
{% endblock %}
like image 403
svprdga Avatar asked Aug 19 '13 09:08

svprdga


1 Answers

You can use an already defined block by writing {{ block('blockName') }}. So for your example you would do it like this:

<title>{% block title %}{% endblock %} | MyBusiness</title>

<meta name="title" content="{{ block('title') }} | MyBusiness"/>

See the documentation which points out nearly exact the same example

like image 62
SirDerpington Avatar answered Oct 04 '22 09:10

SirDerpington