11

I have array like this

{
     "sCode":"05",
     "sCodeName":"critical_tight_connection",
     "iSeverity":1,
     "aData":{
         "iLevelOfDetailt":2,
         "iDuration":35,
         "sLabel":"Labai trumpas pers\u0117dimas, 35 min.",
         "sLink":""
     }
}

i am printing him with smarty (array is not serialized, i ve did it for your сonveniece)

{if !empty( $aSegment.aNotices.aStop )}
    <ul>
        {foreach from=$aSegment.aNotices.aStop item=aNotice}
            <li>
                <img class="{$aNotice.sCodeName}" />
                {$aNotice.sLabel}
            </li>
        {/foreach}
    </ul>
{/if}

how to check with smarty if '05' is exist in aNotices.aStop.sCode ? (before foreach cycle)

Tried this

{if in_array('05', $aSegment.aNotices.aStop)}
    exist
{/if}
2
  • Maybe {php} and {/php} around the if statement helps. Jan 18, 2013 at 14:47
  • @Bondye no, that is not right.
    – Prisoner
    Jan 18, 2013 at 14:53

3 Answers 3

32

you can use this :

{if '05'|in_array:$aSegment.aNotices.aStop}EXIST{/if}
2
  • 6
    Worked like charm {if $smarty.session.user.group|in_array:['admin','broker']} Apr 4, 2016 at 11:15
  • how to ignore the case.? Jan 17, 2023 at 9:10
3

Do you mean something like this?

{if $aNotice.sCode == '05'} ....
0
0

Thank you hek2mgl and Jeff Bic, modified your answers and this works fine :

{if !$aSegment.aNotices.aStop|@count gt 0}
    {t lang='en'}Stop duration{/t}{if $server.lang != 'en'} / {t}Stop duration{/t}{/if}: {$aSector.aStops.$iSegmentIndex|mins_to_time}
{/if}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.