A
A
Alexey Alekseev2019-05-11 14:25:10
symfony
Alexey Alekseev, 2019-05-11 14:25:10

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 %}
-//-

2. index.html.twig
{% extends 'base.html.twig' %}

{% block body %}
-//-
{% set TestVar = 'testvalue' %}  // Назначаем значение переменной
-//-
{% endblock %}

How can you display the value of a variable in the parent if it is defined in the child template?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
virtex2000, 2019-05-14
@virtex2000

index.html.twig

{% extends 'base.html.twig' %}

{% block footer %}
{% set TestVar = 'testvalue' %}  // Назначаем значение переменной
{{ parent() }}
{% endblock %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question