smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.23k stars 703 forks source link

Containment operators #937

Closed wisskid closed 4 months ago

wisskid commented 5 months ago

Support for:

{if $i in [1, 2, 3]}...{/if}

and

{if $j not in [1, 2, 3]}...{/if}
wisskid commented 5 months ago

This could be extended to strings as well: {if 'im' in $name}..{/if}

scottchiefbaker commented 5 months ago

I like this idea a lot... Would it also work for:

{if $needle in $haystack_array}
wisskid commented 5 months ago

@scottchiefbaker yes

wisskid commented 5 months ago

It seems Smarty v5 also supports in_array as a function. (implemented as FunctionHandler.) This is undocumented.

wisskid commented 4 months ago

Wow, this is funny. From the changelog in 2009: - added {if 'expression' is in 'array'} syntax This is undocumented, and we do not have {if 'expression' is not in 'array'} yet.