summaryrefslogtreecommitdiff
path: root/smarty_bit/block.repeat.php
blob: 1eb200e664b3145f49022e4f83e92086c3054c2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: block.repeat.php
* Type: block
* Name: repeat
* Purpose: repeat a template block a given number of times
* Parameters: count [required] - number of times to repeat
* assign [optional] - variable to collect output
* Author: Scott Matthewman <scott@matthewman.net>
* -------------------------------------------------------------
*/
function smarty_block_repeat( $params, $content, &$smarty ) {
	if( !empty( $content ) ) {
		$intCount = intval( $params['count'] );
		if( $intCount < 0 ) {
			$smarty->trigger_error( "block: negative 'count' parameter" );
			return;
		}

		$strRepeat = str_repeat( $content, $intCount );
		if( !empty( $params['assign'] ) ) {
			$smarty->assign($params['assign'], $strRepeat );
		} else {
			echo $strRepeat;
		}
	}
}
?>