[TWIG] IF-problem for task- and item-array-values

Hey guys, me again.

I need help with coding in TWIG.

I’m creating an invoice-design and I replaced the standard-item-table-code by some twig-enhanced item-tables. BUT …

… how can i code it that one table (item, task, whatever) will only be shown if there is at least one item-line? Or in shorter words: How to hide empty tables?

In my thoughts it must have something to do with

{% if (invoice.line_items | filter(item => item.type_id == 2)) | e } then show table …

But I don’t find the right way.

Thanks a lot for any help!

Hi,

@david can you please advise?

You can use the length filter something like this should work:


 (invoice.line_items | filter(item => item.type_id == 2)) | length > 0  

2 Likes

Seems to be working, thank you very much, @david