diff options
| author | Kevin Chabowski <kevin@kch42.de> | 2012-06-27 21:09:07 +0200 | 
|---|---|---|
| committer | Kevin Chabowski <kevin@kch42.de> | 2012-06-27 21:09:07 +0200 | 
| commit | d0b7317e10254490acbe748d1d8c1e04aaf8be6b (patch) | |
| tree | 19d484bee311b488aa75212ce0f31d6ae29b4308 /stupid_template_engine.php | |
| parent | 06eea058aac1b3edbd526474ce71bfe47194fb46 (diff) | |
| download | ste-d0b7317e10254490acbe748d1d8c1e04aaf8be6b.tar.gz ste-d0b7317e10254490acbe748d1d8c1e04aaf8be6b.tar.bz2 ste-d0b7317e10254490acbe748d1d8c1e04aaf8be6b.zip | |
Added new Tags to the standard library.
* ste:in_array checks, if a value is in an array
* ste:join joins an array with a glue string
* ste:split splits a string with a delimiter to an array
* ste:array_add adds an element to an array.
Diffstat (limited to 'stupid_template_engine.php')
| -rw-r--r-- | stupid_template_engine.php | 38 | 
1 files changed, 38 insertions, 0 deletions
| diff --git a/stupid_template_engine.php b/stupid_template_engine.php index 6acb6d7..e8e78ec 100644 --- a/stupid_template_engine.php +++ b/stupid_template_engine.php @@ -1396,6 +1396,44 @@ class STEStandardLibrary  	{  		return @strftime($sub($ste), empty($params["timestamp"]) ? @time() : (int) $params["timestamp"]);  	} +	 +	static public function in_array($ste, $params, $sub) +	{ +		if(empty($params["array"])) +			throw new RuntimeError("Missing array parameter in <ste:in_array>."); +		$ar = &$ste->get_var_reference($params["array"], False); +		if(!is_array($ar)) +			return ""; +		return in_array($sub($ste), $ar) ? "y" : ""; +	} +	 +	static public function join($ste, $params, $sub) +	{ +		if(empty($params["array"])) +			throw new RuntimeError("Missing array parameter in <ste:join>."); +		return implode($sub($ste), $ste->get_var_by_name($params["array"])); +	} +	 +	static public function split($ste, $params, $sub) +	{ +		if(empty($params["array"])) +			throw new RuntimeError("Missing array parameter in <ste:split>."); +		if(empty($params["delim"])) +			throw new RuntimeError("Missing delim parameter in <ste:split>."); +		$ste->set_var_by_name($params["array"], explode($params["delim"], $sub($ste))); +	} +	 +	static public function array_add($ste, $params, $sub) +	{ +		if(empty($params["array"])) +			throw new RuntimeError("Missing array parameter in <ste:array_add>."); +		 +		$ar = &$ste->get_var_reference($params["array"], True); +		if(empty($params["key"])) +			$ar[] = $sub($ste); +		else +			$ar[$params["key"]] = $sub($ste); +	}  }  ?>
\ No newline at end of file | 
