FortuneSoldier
FortuneSoldier

Reputation: 508

How to see if a value for the key filter exists or not in twig?

I am a newbie in using twig. How to check if value "filter" exists or not from twig ?

    ParameterBag {#10 ▼
  #parameters: array:1 [▼
    "filter" => "news"
  ]
}

This is what I got from calling {{ dump(app.request.query) }}

Upvotes: 0

Views: 325

Answers (2)

Zahori
Zahori

Reputation: 446

Try

{% if foo %}
    ...
{% endif %}

Or if it's an array and you want to know if it's not empty, try

{% if foo is not empty %}
    ...
{% endif %}

Upvotes: 3

FortuneSoldier
FortuneSoldier

Reputation: 508

I have found an answer to this question while browsing through the net.

{% if foo is empty %}
    ...
{% endif %} 

This is my answer.

Upvotes: 0

Related Questions