mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 19:06:40 +00:00
02b084e2f5c3119604b1c0da388dd2438a012191
This PR was merged into the 1.x branch.
Discussion
----------
added support for a custom template on the block() function
`block()` allows one to render a block of the current template.
This PR adds the possibility to use `block()` to render a block of another template:
```twig
{{ block('footer', template_name) }}
```
As it uses the same logic as for the regular `block()`, you can also use it in a test:
```twig
{% if block('footer', template_name) is defined %}
...
{% endif %}
```
This removes the needs to use the internal `Twig_Template::renderBlock()` method in the Symfony Web Profiler for instance. And combined with #2236, it allows us to really mark the whole `Twig_Template` class as being internal.
I'm aware that #1302 asked for being able to pass a context to `block()` (implemented in #1433), but I prefer not to in favor of adding the `with` tag (see #719 and #1054).
When the `with` will be implemented, the code in the Symfony Web Profiler will become something along the lines of:
```twig
{% with {
'collector': profile.getcollector(name),
'profiler_url': profiler_url,
'token': profile.token,
'name': name
} %}
{{ block('toolbar', template) }}
{% endwith %}
```
Commits
-------
5ed59be added support for a custom template on the block() function
Twig, the flexible, fast, and secure template language for PHP ============================================================== Twig is a template language for PHP, released under the new BSD license (code and documentation). Twig uses a syntax similar to the Django and Jinja template languages which inspired the Twig runtime environment. More Information ---------------- Read the `documentation`_ for more information. .. _documentation: http://twig.sensiolabs.org/documentation
Description
Languages
PHP
99.9%