Answer the question
In order to leave comments, you need to log in
How to pass variable value from child template to parent template in Twig?
We have 2 Twig templates:
1. base.html.twig
-//-
{% block body %}
{% endblock %}
{% block footer %}
{{ TestVar }} // Необходимо вывести значение переменной, которую определили в index.html.twig
{% endblock %}
-//-
{% extends 'base.html.twig' %}
{% block body %}
-//-
{% set TestVar = 'testvalue' %} // Назначаем значение переменной
-//-
{% endblock %}
Answer the question
In order to leave comments, you need to log in
index.html.twig
{% extends 'base.html.twig' %}
{% block footer %}
{% set TestVar = 'testvalue' %} // Назначаем значение переменной
{{ parent() }}
{% endblock %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question