I
I
infastin2015-03-27 09:41:39
PHP
infastin, 2015-03-27 09:41:39

How to use Twig block content twice in PHP?

Is it possible to use the contents of a Twig block twice in PHP?
If you do this:

<title>{% block title %}{% endblock %}</title>
<h1>{% block title %}{% endblock %}</h1>

Gives an error message:
Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'The block 'title' has already been defined line 7 in "base.layout" at line 58'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2015-03-27
@infastin

<title>{% block title %}{% endblock %}</title>
<h1>{{ block('title') }}</h1>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question