Twig: Blocks with the same name should be allowed to promote reuse

Created on 21 Nov 2017  路  3Comments  路  Source: twigphp/Twig

Consider the following template:

<html>
<head>
    <title>{% block title %}{% endblock %}</title>
<body>
    <h1>{% block title %}{% endblock %}</h1>

Clearly the goal here is to have the title block substituted identically in both places. However, this causes a compile error:

[Twig_Error_Syntax]: The block 'title' has already been defined line 3.

I propose identical blocks with the same name should be allowed to promote reuse.

Most helpful comment

Why not replacing the second one with {{聽block('title') }}?

All 3 comments

Why not replacing the second one with {{聽block('title') }}?

Oh, I see, I was not aware of a block function. It might be useful if that was mentioned in either the block tag or extends tag documentation, for those unaware. Thanks for the tip!

@Bilge Can you submit a PR to improve the docs?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

su-narthur picture su-narthur  路  6Comments

scila1996 picture scila1996  路  3Comments

xxfaxy picture xxfaxy  路  6Comments

Seldaek picture Seldaek  路  6Comments

garak picture garak  路  5Comments