mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
update cycle function to allow blank values parameter after initialized
This commit is contained in:
@@ -5,13 +5,15 @@
|
|||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
* Type: function
|
* Type: function
|
||||||
* Name: cycle
|
* Name: cycle
|
||||||
* Version: 1.1
|
* Version: 1.2
|
||||||
|
* Date: May 3, 2002
|
||||||
* Author: Monte Ohrt <monte@ispi.net>
|
* Author: Monte Ohrt <monte@ispi.net>
|
||||||
* Credits: Mark Priatel <mpriatel@rogers.com>
|
* Credits: Mark Priatel <mpriatel@rogers.com>
|
||||||
* Gerard <gerard@interfold.com>
|
* Gerard <gerard@interfold.com>
|
||||||
* Purpose: cycle through given values
|
* Purpose: cycle through given values
|
||||||
* Input: id = id of cycle (optional)
|
* Input: id = id of cycle (optional)
|
||||||
* values = comma separated list of values to cycle
|
* values = comma separated list of values to cycle
|
||||||
|
* (this can be left out for subsequent calls)
|
||||||
* reset = boolean - resets given var to true
|
* reset = boolean - resets given var to true
|
||||||
* print = boolean - print var or not. default is true
|
* print = boolean - print var or not. default is true
|
||||||
* advance = boolean - whether or not to advance the cycle
|
* advance = boolean - whether or not to advance the cycle
|
||||||
@@ -21,10 +23,13 @@
|
|||||||
*
|
*
|
||||||
* Examples: {cycle values="#eeeeee,#d0d0d0d"}
|
* Examples: {cycle values="#eeeeee,#d0d0d0d"}
|
||||||
* {cycle id=row values="one,two,three" reset=true}
|
* {cycle id=row values="one,two,three" reset=true}
|
||||||
|
* {cycle id=row}
|
||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
function smarty_function_cycle($params, &$smarty)
|
function smarty_function_cycle($params, &$smarty)
|
||||||
{
|
{
|
||||||
|
static $cycle_vars;
|
||||||
|
|
||||||
extract($params);
|
extract($params);
|
||||||
|
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
@@ -44,32 +49,38 @@ function smarty_function_cycle($params, &$smarty)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array('values', array_keys($params))) {
|
if (!in_array('values', array_keys($params))) {
|
||||||
$smarty->trigger_error("cycle: missing 'values' parameter");
|
if(!isset($cycle_vars[$id]['values'])) {
|
||||||
return;
|
$smarty->trigger_error("cycle: missing 'values' parameter");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
static $cycle_vars;
|
} else {
|
||||||
|
if(isset($cycle_vars[$id]['values'])
|
||||||
|
&& $cycle_vars[$id]['values'] != $values ) {
|
||||||
|
$cycle_vars[$id]['index'] = 0;
|
||||||
|
}
|
||||||
|
$cycle_vars[$id]['values'] = $values;
|
||||||
|
}
|
||||||
|
|
||||||
$cycle_array = explode($delimiter,$values);
|
$cycle_array = explode($delimiter,$cycle_vars[$id]['values']);
|
||||||
|
|
||||||
if(!isset($cycle_vars[$id]) || $reset ) {
|
if(!isset($cycle_vars[$id]['index']) || $reset ) {
|
||||||
$cycle_vars[$id] = 0;
|
$cycle_vars[$id]['index'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($assign)) {
|
if (isset($assign)) {
|
||||||
$print = false;
|
$print = false;
|
||||||
$smarty->assign($assign, $cycle_array[$cycle_vars[$id]]);
|
$smarty->assign($assign, $cycle_array[$cycle_vars[$id]['index']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($print) {
|
if($print) {
|
||||||
echo $cycle_array[$cycle_vars[$id]]."\n";
|
echo $cycle_array[$cycle_vars[$id]['index']]."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($advance) {
|
if($advance) {
|
||||||
if ( $cycle_vars[$id] >= count($cycle_array) -1 ) {
|
if ( $cycle_vars[$id]['index'] >= count($cycle_array) -1 ) {
|
||||||
$cycle_vars[$id] = 0;
|
$cycle_vars[$id]['index'] = 0;
|
||||||
} else {
|
} else {
|
||||||
$cycle_vars[$id]++;
|
$cycle_vars[$id]['index']++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,13 +5,15 @@
|
|||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
* Type: function
|
* Type: function
|
||||||
* Name: cycle
|
* Name: cycle
|
||||||
* Version: 1.1
|
* Version: 1.2
|
||||||
|
* Date: May 3, 2002
|
||||||
* Author: Monte Ohrt <monte@ispi.net>
|
* Author: Monte Ohrt <monte@ispi.net>
|
||||||
* Credits: Mark Priatel <mpriatel@rogers.com>
|
* Credits: Mark Priatel <mpriatel@rogers.com>
|
||||||
* Gerard <gerard@interfold.com>
|
* Gerard <gerard@interfold.com>
|
||||||
* Purpose: cycle through given values
|
* Purpose: cycle through given values
|
||||||
* Input: id = id of cycle (optional)
|
* Input: id = id of cycle (optional)
|
||||||
* values = comma separated list of values to cycle
|
* values = comma separated list of values to cycle
|
||||||
|
* (this can be left out for subsequent calls)
|
||||||
* reset = boolean - resets given var to true
|
* reset = boolean - resets given var to true
|
||||||
* print = boolean - print var or not. default is true
|
* print = boolean - print var or not. default is true
|
||||||
* advance = boolean - whether or not to advance the cycle
|
* advance = boolean - whether or not to advance the cycle
|
||||||
@@ -21,10 +23,13 @@
|
|||||||
*
|
*
|
||||||
* Examples: {cycle values="#eeeeee,#d0d0d0d"}
|
* Examples: {cycle values="#eeeeee,#d0d0d0d"}
|
||||||
* {cycle id=row values="one,two,three" reset=true}
|
* {cycle id=row values="one,two,three" reset=true}
|
||||||
|
* {cycle id=row}
|
||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
function smarty_function_cycle($params, &$smarty)
|
function smarty_function_cycle($params, &$smarty)
|
||||||
{
|
{
|
||||||
|
static $cycle_vars;
|
||||||
|
|
||||||
extract($params);
|
extract($params);
|
||||||
|
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
@@ -44,32 +49,38 @@ function smarty_function_cycle($params, &$smarty)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array('values', array_keys($params))) {
|
if (!in_array('values', array_keys($params))) {
|
||||||
$smarty->trigger_error("cycle: missing 'values' parameter");
|
if(!isset($cycle_vars[$id]['values'])) {
|
||||||
return;
|
$smarty->trigger_error("cycle: missing 'values' parameter");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
static $cycle_vars;
|
} else {
|
||||||
|
if(isset($cycle_vars[$id]['values'])
|
||||||
|
&& $cycle_vars[$id]['values'] != $values ) {
|
||||||
|
$cycle_vars[$id]['index'] = 0;
|
||||||
|
}
|
||||||
|
$cycle_vars[$id]['values'] = $values;
|
||||||
|
}
|
||||||
|
|
||||||
$cycle_array = explode($delimiter,$values);
|
$cycle_array = explode($delimiter,$cycle_vars[$id]['values']);
|
||||||
|
|
||||||
if(!isset($cycle_vars[$id]) || $reset ) {
|
if(!isset($cycle_vars[$id]['index']) || $reset ) {
|
||||||
$cycle_vars[$id] = 0;
|
$cycle_vars[$id]['index'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($assign)) {
|
if (isset($assign)) {
|
||||||
$print = false;
|
$print = false;
|
||||||
$smarty->assign($assign, $cycle_array[$cycle_vars[$id]]);
|
$smarty->assign($assign, $cycle_array[$cycle_vars[$id]['index']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($print) {
|
if($print) {
|
||||||
echo $cycle_array[$cycle_vars[$id]]."\n";
|
echo $cycle_array[$cycle_vars[$id]['index']]."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($advance) {
|
if($advance) {
|
||||||
if ( $cycle_vars[$id] >= count($cycle_array) -1 ) {
|
if ( $cycle_vars[$id]['index'] >= count($cycle_array) -1 ) {
|
||||||
$cycle_vars[$id] = 0;
|
$cycle_vars[$id]['index'] = 0;
|
||||||
} else {
|
} else {
|
||||||
$cycle_vars[$id]++;
|
$cycle_vars[$id]['index']++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user