I don't think its a good idea to put any business logic inside your template. If you need the boy object in your parent theme, you should define it in your controller instead and pass it to the template. Both the parent and child templates can access that object.
Passing parameters in twig (from template to another template)
-
19-09-2022 - |
Question
Parent:
{% block row -%}{% endblock %}
Child:
{% block row -%}
{{ parent() }}
{% set boy = {
'name': 'foo',
'age': 12,
}
%}
{% endblock %}
My question is, how do I pass the boy object to the Parent (without losing its value)?
La solution
Autres conseils
You can do something like:
{% extends 'ProjectCommonBundle:Email:base.html.twig' %}
{# set the vars you need on your base layout #}
{% set organization = organization %}
{% set emailTo = emailTo %}
{% block body %}
{% endblock %}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow