Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use in_array and isset in twig template?

Tags:

php

twig

This part:

<?php if (isset($quantity_taxation_curr) && in_array($currency['code'], $quantity_taxation_curr)) { ?>

to become in twig format, I tried with this:

{% if isset(quantity_taxation_curr) AND in_array(currency['code'], quantity_taxation_curr) %}

But it's not correct.

like image 339
MorganFreeFarm Avatar asked Sep 17 '25 21:09

MorganFreeFarm


2 Answers

Try this:

{% if quantity_taxation_curr is defined and currency['code'] in quantity_taxation_curr %}
like image 176
cn007b Avatar answered Sep 20 '25 12:09

cn007b


Try this out

{% if quantity_taxation_curr is defined and 'code' in quantity_taxation_curr %}
...
{% endif %}
like image 28
teeyo Avatar answered Sep 20 '25 10:09

teeyo