S
S
Sergey Miller2020-09-06 23:05:17
Twig
Sergey Miller, 2020-09-06 23:05:17

How to create a variable in Twig and assign it a value from another variable?

{% if mpn %} // если есть переменная
{{ mpn }} // то вывожу ее

{% set collectionname = '{{mpn}}' %} // и устанавливаю новую переменную, присвоив ей значение из переменной "{{ mpn }}"

коллекция - {{ collectionname }} - // но в итоге выводится не само значение, а голый прям текст - {{ mpn }}

{% endif %}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Miller, 2020-09-06
@blackseabreathe

For those who came here with the same question:
when setting a variable and assigning it a value from another variable, you need to specify the variable from which we want to get the value. without quotes and brackets
Incorrect: Correct:
{% set collectionname = '{{mpn}}' %}
{% set collectionname = mpn %}

R
Rsa97, 2015-08-25
@Rsa97

Wangyu - either the body of the letter, or some of the To, Subject, From or Date fields changed after signing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question