Tag {if $value in $array} ParseError syntax error, unexpected identifier “in”
- m.brecher
- Generous Backer | 864
Hello,
I have seen somewhere on github this interesting latte tag {if $value in $array}:
{var $inputClass = $input::class}
{if $inputClass in ['Nette\Forms\Controls\SubmitButton', ....]} // this only one syntax works
.......
{/if}
The code sample above works well, although I have not found this tag {if $value in $array} in the official Latte documentation. But only some of syntax cases works, many dont – see samples:
{var $inputClass = $input::class}
{var $buttonClasses = ['Nette\Forms\Controls\SubmitButton', ....]}
{if $inputClass in $buttonClasses} // ParseError
.......
{/if}
{if $input::class in ['Nette\Forms\Controls\SubmitButton', ....]} // ParseError too
.......
{/if}
The syntax “if in” is cool and I like it, but the support for that syntax is weak.
My question is – is this syntax an latte official one, or not?
I propose to complete the support and add into the documentation.
Thanks
Last edited by m.brecher (2022-10-07 23:07)
- David Grudl
- Nette Core | 8218
The PHP way would be !$value in $array
, similary to
!$value instanceof Abc
. Or add an operator
not in
…