Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 20623 программиста и 978 роботов. Сейчас ищут 703 программиста ...

{foreach:variable,key,value}

Вернуться к: HTML_Template_Flexy

{foreach:variable,key,value}

{foreach:variable,key,value} – creates a PHP foreach loop

Synopsis

Usage ( {foreach:variable,key,value} , {foreach:variable,value} )

creates a foreach loop, needs an {end:} tag. note that the engine will add the variable to the scope, so they will not be prefixed with $t-> when used inside the loop.

Parameter

  • string variable - relates to $object->variable

  • string key - creates a variable 'key' in the current scope.

  • string value - optionally creates a variable 'value' in the current scope. (as in $key=>$value)

Example

Setting variables for foreach

           $this->a = array(   "dog" => "cat",   "fire" => "water" ); $this->b = array('a','b','c');  $template->outputObject($this);

Foreach in template

            {foreach:a,k,v}   k is {k}, and v is {v} {end:} {foreach:b,v}   v is {v} {end:}

Compiled template

                  <?php if (is_array($t->a)) foreach($t->a as $k => $v) { ?>   k is <?php echo htmlspecialchars($k); ?>, and v is <?php echo htmlspecialchars($v); ?> <?php } ?> <?php if (is_array($t->a)) foreach($t->b as $v) { ?>   v is <?php echo htmlspecialchars($v); ?> <?php } ?>

example output

                 k is dog, v is cat k is fire, v is water v is a v is b v is c


Вернуться к: HTML_Template_Flexy

© 2024 «PHP.RU — Сообщество PHP-Программистов»
Главная | Форум | Реклама на сайте | Контакты VIP Сувениры
Разработка компании ODware