stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.34k stars 223 forks source link

Support {% if item in list %} #142

Closed kdawgwilk closed 6 years ago

kdawgwilk commented 6 years ago

I have been wishing I could do something list the following in Stencil templates

{% if item in list%}
// Do stuff here now that we know this is in the list
{% endif %}
kdawgwilk commented 6 years ago

I initially brought this up over in Sourcery krzysztofzablocki/Sourcery#415

AliSoftware commented 6 years ago

Couldn't you just do {% if list|contains:item %}? Or does that contains filter not work with arrays but only strings?

kdawgwilk commented 6 years ago

I have not tried this but I will give it a go

ilyapuchka commented 6 years ago

@AliSoftware @kdawgwilk according to StencilSwiftKit code it looks like it is indeed defined only on strings