String Repeat

Author: Ken Stanley <smarty@kennethpaul.com>

This plugin gives you the same results as the native PHP function str_repeat does. There

are three attributes to the function: STRING (String to repeat) and COUNT (How many times to repeat) and ASSIGN which allows you to stuff the results into a template variable to use

as many times throughout the template as you wish.

<?php

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     str_repeat
 * Author:   Ken Stanley <smarty@kennethpaul.com>
 * Purpose:  print out a value x amount of times
 * -------------------------------------------------------------
 */
function smarty_function_str_repeat($params, &$smarty)
{
    static $string = array();
    static $count = array();
    static $assign = "";

    extract($params);
    
    if (!empty($assign))
        $smarty->assign($assign, str_repeat($string[0],$count[0]));
    else
        echo str_repeat($string[0],$count[0]);
}
?>

Back to SmartyPlugins?.