dropoff Posted August 1, 2012 Report Share Posted August 1, 2012 (edited) Доброго времени суток.Ребята, такой вопрос.Ест массивarray( 'title' => название, 'status' => 1, 'opt' => array( 'opt_name' => 0, ),)в шаблоне{foreach $arr AS $a}{$a.title}<br /> {foreach $a.opt AS $o} ... {/foreach}{/foreach}и мне нужно ВНЕ этих циклов узнать, есть ли в массиве opt значения 1(единиц)т.е. если там есть хоть одно значение 1, то нужно выводить определенный текст.Пример{if $opt > 0}Есть опции{/if}Как-то можно это сделать? В доках smarty ничего похожего не нашел. Edited August 1, 2012 by dropoff Quote Link to comment Share on other sites More sharing options...
0 Great Rash Posted August 1, 2012 Report Share Posted August 1, 2012 {if $arr.opt|@count > 0}Есть!{/if}Может так??? Quote Link to comment Share on other sites More sharing options...
0 dropoff Posted August 1, 2012 Author Report Share Posted August 1, 2012 Простите, не правильно составил массив.Обновил первый топик.Мне нужно проверять есть ли в массиве opt хоть одно значение opt_name с 1(единицей) Quote Link to comment Share on other sites More sharing options...
0 dropoff Posted August 1, 2012 Author Report Share Posted August 1, 2012 Так можно как-то сделать? Сколько разных вариантов пробовал - ничего не выходит. И доки smarty не очень в этом плане. Quote Link to comment Share on other sites More sharing options...
0 Great Rash Posted August 1, 2012 Report Share Posted August 1, 2012 Вообще в смарти работают обычные PHP функции. Попробуйте заюзать, скажем in_array. Quote Link to comment Share on other sites More sharing options...
0 dropoff Posted August 1, 2012 Author Report Share Posted August 1, 2012 php выключен и в шаблонах его не использую вообще. думал именно через smarty сделать. но так и не понял как. Quote Link to comment Share on other sites More sharing options...
Question
dropoff
Доброго времени суток.
Ребята, такой вопрос.
Ест массив
в шаблоне
{foreach $arr AS $a}{$a.title}<br />
{foreach $a.opt AS $o}
...
{/foreach}
{/foreach}
и мне нужно ВНЕ этих циклов узнать, есть ли в массиве opt значения 1(единиц)
т.е. если там есть хоть одно значение 1, то нужно выводить определенный текст.
Пример
{if $opt > 0}Есть опции{/if}
Как-то можно это сделать? В доках smarty ничего похожего не нашел.
Edited by dropoffLink to comment
Share on other sites
5 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.