We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

how to use php function: in_array in volt

How to use in_array in volt



58.4k
Accepted
answer

Hi

You can define variable load function php in volt

        //load function php
        $compiler = $volt->getCompiler();
        //define variable translate
        $compiler->addFunction('in_array', 'in_array');

https://github.com/duythien/blog/blob/master/app/config/services.php

edited May '16

:) That is true, but there is "native" way (not need function to add) xD. Example in volt (variable menu contain string, tmp_dropdown is array- they can be defined in controller):

{% set tmp_dropdown = ['menu', 'texts', 'broadcasts'] %}
{% set menu = 'texts' %}

{% if menu in tmp_dropdown %}YES{% endif %}