I have been trying to figure out how to use the if not
clause with Twig template engine.
According to the documents:
You can also use not to check for values that evaluate to false:
So I'm trying to use it like this:
{% if not signed_in %}
You are not signed in.
{% endif %}
And signed_in
comes from a middleware. Looking like this:
if (!$this->container->auth->check()) {
/* Render a Sign-up */
return $this->container->view->render($response, 'subscriber/index.twig', ['signed_in' => false]);
}
So if I {{ dump(signed_in) }}
when I'm not signed in it returns false
. But when I'm signed in, singed_in
returns null
.
The current solution I'm going with is {% if signed_in is defined %}
, but that is actually not what I'm looking for, or is it?
Twig != is a comparison operator.
The following comparison operators are supported in any expression: ==, !=, <, >, >=, and <=
You can use != to compare any two things that php lets you compare, and what you get back is a boolean.
Twig not is a logic operator. (so are and and or)
not: Negates a statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With