svprdga
svprdga

Reputation: 2529

Repeating block in 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 %}

Upvotes: 9

Views: 6284

Answers (1)

SirDerpington
SirDerpington

Reputation: 11460

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

Upvotes: 31

Related Questions