From 56196c68fdbef92c6d24f100e52530e07ac01822 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Fri, 1 Jun 2012 11:35:13 +0200 Subject: Implemented on_* tags. UNTESTED! on_article / on_tag / on_section will execute and return its content, if currently a(n) article / tag / section is requested. --- ratatoeskr/frontend.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/ratatoeskr/frontend.php b/ratatoeskr/frontend.php index 038485a..13fd14a 100644 --- a/ratatoeskr/frontend.php +++ b/ratatoeskr/frontend.php @@ -654,6 +654,55 @@ $ste->register_tag("title", function($ste, $params, $sub) return "$pagetitle"; }); +function make_on_anything_tag($field) +{ + return function($ste, $params, $sub) use ($field) + { + if($ste->evalbool($ste->vars["current"][$field])) + { + if(!empty($params["var"])) + $ste->set_var_by_name($params["var"], $ste->vars["current"][$field]); + return $sub($ste); + } + }; +} + +/* + * STETag: on_article + * Execute tag content, if currently an article is requested. + * + * Parameters: + * var - (optional) If set, the article will be stored in the variable with that name (see for sub-fields). + * + * Returns: + * The executed tag content, if an article was requested. + */ +$ste->register_tag("on_article", make_on_anything_tag("article")); + +/* + * STETag: on_tag + * Execute tag content, if currently a tag is requested. + * + * Parameters: + * var - (optional) If set, the tag will be stored in the variable with that name (see for sub-fields). + * + * Returns: + * The executed tag content, if a tag was requested. + */ +$ste->register_tag("on_tag", make_on_anything_tag("tag")); + +/* + * STETag: on_section + * Execute tag content, if currently a section is requested. + * + * Parameters: + * var - (optional) If set, the section will be stored in the variable with that name (see for sub-fields). + * + * Returns: + * The executed tag content, if a section was requested. + */ +$ste->register_tag("on_section", make_on_anything_tag("section")); + /* * STEVar: $current * Holds information about the current page in the frontend (the part of the webpage, the visitor sees). -- cgit v1.2.3-70-g09d2