smarty icon indicating copy to clipboard operation
smarty copied to clipboard

Containment operators

Open wisskid opened this issue 1 year ago • 5 comments

Support for:

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

and

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

wisskid avatar Feb 24 '24 22:02 wisskid

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

wisskid avatar Feb 24 '24 22:02 wisskid

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

{if $needle in $haystack_array}

scottchiefbaker avatar Feb 24 '24 23:02 scottchiefbaker

@scottchiefbaker yes

wisskid avatar Feb 25 '24 00:02 wisskid

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

wisskid avatar Feb 25 '24 10:02 wisskid

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.

wisskid avatar Mar 18 '24 15:03 wisskid