N
N
Nikita Kolesnikov2018-12-09 14:16:43
Twig
Nikita Kolesnikov, 2018-12-09 14:16:43

Why doesn't if work properly in twig?

Hello
Either I'm doing something wrong, or something is wrong with twig...
A boolean variable is passed from the year, it is checked in the template, and depending on its state, the code should be executed:

{% if status == true %}
    <p>Test.</p>
{% endif %}

This code does not work, even though the variable will be true, even false, but if you do this:
{% if status == false %}
    <p>Test.</p>
{% endif %}

The condition is met regardless, true or false in the variable
UPD:
I found the cause of the error ('-' in the variable name is also an error), but I don’t know how to fix it.
I needed to pass data to the template from two arrays, I used array_push to merge, but it gives an array in a form that twig does not understand.
var_dump output of an array that twig understands (before merging via array_push):
array(1) { ["user_status"]=> string(1) bool(true) }

Array var_dump output that twig doesn't understand (after merging via array_push):
array(1) { ["user_status"]=> string(1) bool(true) }

Question: how to make an array understandable for twig'a?
____
Using one array is not an option, because the first contains data from the controller, and the second from the auxiliary class, which works on almost all pages, pushing it into each controller is somehow stupid...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tom Nolane, 2018-12-09
@NikitOS_MV

are you sure you spelled it stauscorrectly? may need status?
upd
1) try redefining the variable from user-statusto user_status(everywhere)
2) or the variable <code>user-status</code>is not passed to the view

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question