viewconditional-statementstemplate-talphptal

how can i check if a php associative array's key is equal to a defined variable from phptal condition?


i've this problem my phptal view has a variable called data which is an associative array.

Let's suppose that i've those Keys M01 M02 and M03 not in a particular order, i've to print to the user view all the data not referred by key M02.

How can i do this? Thanks in advance

Marco

UPDATE: I forgot to say that i cannot edit the code which calls the view.


Solution

  • If order is important, use second array with ordered keys to print:

    <div tal:repeat="key php:array('M01','M03')" tal:content="array/$key"/>
    

    Otherwise you can just add a condition:

    <div tal:repeat="data array">
        <tal:block tal:condition="php:repeat.data.key != 'M02'" tal:content="data"/>
    </div>