Duplicate block in Twig

Is there a way to repeat one block in twig like this:

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

To declare only two blocks once? For instance:

 {% block title %} The title I want to show in each title and metaTitle tags.{{ parent() }} {% endblock %} 
+4
source share
1 answer

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 documentation that shows an almost exact example.

+21
source

Source: https://habr.com/ru/post/1497765/


All Articles