-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the render function, deprecate the include one #4434
base: 3.x
Are you sure you want to change the base?
Conversation
cfd3254
to
8c1dac8
Compare
Maybe it would be good to also deprecate the |
8c1dac8
to
e62c09c
Compare
@fabpot wanted to give some feedback. I really like the new include decision without context by default. Even I'm not a fan of renaming it Typically looks like this: {# overlay.html.twig #}
<dialog>
<h3>
{% block title %}{% endblock %}
</h3>
<div>
{% block content %}{% endblock %}
</div>
</dialog> {# using.html.twig #}
{% set title = 'Title' %}
{% set content = 'Content' %}
{% embed "overlay.html.twig" only %}
{% block title %}
{{ title }} {# not available #}
{% endblock %}
{% block content %}
<div>
{{ content }} {# not available #}
</div>
{% endblock %}
{% endembed %} To get this work I need give the variables also to overlay.html.twig which may have similar variables defined. {# using.html.twig #}
{% set title = 'Title' %}
{% set content = 'Content' %}
{% embed "overlay.html.twig" {title: title, content: content} only %}
{% block title %}
{{ title }}
{% endblock %}
{% block content %}
<div>
{{ content }}
</div>
{% endblock %}
{% endembed %} So it is a little bit strange. That I need to give the variables to the {# using.html.twig #}
{% set title = 'Title' %}
{% set content = 'Content' %}
{% embed "overlay.html.twig" only %}
{% block title %}
{{ title }} {# still have access to this one #}
{% endblock %}
{% block content %}
<div>
{{ content }} {# still have access to this one #}
</div>
{% endblock %}
{% endembed %} Another solution would be maybe make it transparency on the embed block e.g.: {# using.html.twig #}
{% set title = 'Title' %}
{% set content = 'Content' %}
{% embed "overlay.html.twig" only %}
{% embedblock title with { title: title} %}
{{ title }}
{% endembedblock %}
{% embedblock content with { content: content} %}
<div>
{{ content }}
</div>
{% endembedblock %}
{% endembed %} I hope I did make it understandable where the issues with the embed tag is. |
|
@alexander-schranz the Your proposed syntax will not work, because blocks are rendered with the context from the caller (i.e. the parent template). they have no way to access the context of the place including the template. |
@stof I understand that it is a technical challange to change that behaviour. Just wanted to give feedback that from end user perspective it just felled for me strange how it behaves currently. |
@fabpot is the new terminology |
e62c09c
to
9807713
Compare
Maybe we can keep the include function, but add a flag to opt into the new behavior and deprecate not doing so. |
@derrabus technically, that flag already exists in |
Perfect. So let's deprecate not setting that flag to |
I thought @derrabus meant a flag in the configuration, like how you can ignore missing variables. |
@willrowe setting a flag in the Environment is bad, as it expects that the migration is done all at once, including all third-party templates. Switching the behavior of a function through a global state basically makes it unreliable for third-party code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, twig should ship something (rector plugin, raw binary script), to update ours templates
@@ -1,5 +1,7 @@ | |||
# 3.15.0 (2024-XX-XX) | |||
|
|||
|
|||
* Deprecate the `include` function, use `render` instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be good to also deprecate the include tag in 3.15.
Yes, Let's deprecate the include tag too
@lyrixx think twig-cs-fixer from @VincentLanglet can do that work. Upgrading include without_context = false to the new render I think should be possible without lot of effort. Problem is more about include where the context was not false which was default at current state. Sure quickfix could be give everywhere Example: VincentLanglet/Twig-CS-Fixer#327 For such rule it is sure easier if |
{{ render('template.html') }} | ||
{{ render(template_var) }} | ||
|
||
A template can also be an instance of ``\Twig\Template`` or a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing a Template instead of a TemplateWrapper is deprecated, afaik
@@ -0,0 +1,9 @@ | |||
--TEST-- | |||
"include" function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"include" function | |
"render" function |
No description provided.