comanche: generalise the conditional variable usage and add $observer as a test. Update comanche doco to reflect recent changes.
This commit is contained in:
parent
8a2b96c2f9
commit
86dd67f57d
@ -99,7 +99,18 @@ class Comanche {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_condition_var($v) {
|
||||||
|
if($v) {
|
||||||
|
$x = explode('.',$v);
|
||||||
|
if($x[0] == 'config')
|
||||||
|
return get_config($x[1],$x[2]);
|
||||||
|
elseif($x[0] === 'observer')
|
||||||
|
return get_observer_hash();
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function test_condition($s) {
|
function test_condition($s) {
|
||||||
|
|
||||||
@ -112,39 +123,36 @@ class Comanche {
|
|||||||
// [if $config.system.foo] which will check for a return of a true condition for get_config('system','foo');
|
// [if $config.system.foo] which will check for a return of a true condition for get_config('system','foo');
|
||||||
// The values 0, '', an empty array, and an unset value will all evaluate to false.
|
// The values 0, '', an empty array, and an unset value will all evaluate to false.
|
||||||
|
|
||||||
if(preg_match('/[\$]config[\.](.*?)\s\=\=\s(.*?)$/',$s,$matches)) {
|
if(preg_match('/[\$](.*?)\s\=\=\s(.*?)$/',$s,$matches)) {
|
||||||
$x = explode('.',$matches[1]);
|
$x = $this->get_condition_var($matches[1]);
|
||||||
if(get_config(trim($x[0]),trim($x[1])) == trim($matches[2]))
|
if($x == trim($matches[2]))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(preg_match('/[\$]config[\.](.*?)\s\!\=\s(.*?)$/',$s,$matches)) {
|
if(preg_match('/[\$](.*?)\s\!\=\s(.*?)$/',$s,$matches)) {
|
||||||
$x = explode('.',$matches[1]);
|
$x = $this->get_condition_var($matches[1]);
|
||||||
if(get_config(trim($x[0]),trim($x[1])) != trim($matches[2]))
|
if($x != trim($matches[2]))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(preg_match('/[\$]config[\.](.*?)\s\{\}\s(.*?)$/',$s,$matches)) {
|
if(preg_match('/[\$](.*?)\s\{\}\s(.*?)$/',$s,$matches)) {
|
||||||
$x = explode('.',$matches[1]);
|
$x = $this->get_condition_var($matches[1]);
|
||||||
$y = get_config(trim($x[0]),trim($x[1]));
|
if(is_array($x) && in_array(trim($matches[2]),$x))
|
||||||
if(is_array($y) && in_array(trim($matches[2]),$y))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(preg_match('/[\$]config[\.](.*?)\s\{\*\}\s(.*?)$/',$s,$matches)) {
|
if(preg_match('/[\$](.*?)\s\{\*\}\s(.*?)$/',$s,$matches)) {
|
||||||
$x = explode('.',$matches[1]);
|
$x = $this->get_condition_var($matches[1]);
|
||||||
$y = get_config(trim($x[0]),trim($x[1]));
|
if(is_array($x) && array_key_exists(trim($matches[2]),$x))
|
||||||
if(is_array($y) && array_key_exists(trim($matches[2]),$y))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(preg_match('/[\$](.*?)/',$s,$matches)) {
|
||||||
if(preg_match('/[\$]config[\.](.*?)/',$s,$matches)) {
|
$x = $this->get_condition_var($matches[1]);
|
||||||
$x = explode('.',$matches[1]);
|
if($x)
|
||||||
if(get_config(trim($x[0]),trim($x[1])))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -65,17 +65,23 @@ By default, $nav is placed in the "nav" page region and $content is pl
|
|||||||
|
|
||||||
To select a theme for your page, use the 'theme' tag.
|
To select a theme for your page, use the 'theme' tag.
|
||||||
[code]
|
[code]
|
||||||
[theme]apw[/theme]
|
[theme]suckerberg[/theme]
|
||||||
|
|
||||||
[/code]
|
[/code]
|
||||||
This will select the theme named "apw". By default your channel's preferred theme will be used.
|
This will select the theme named "suckerberg". By default your channel's preferred theme will be used.
|
||||||
|
|
||||||
[code]
|
[code]
|
||||||
[theme=passion]apw[/theme]
|
[theme=passion]suckerberg[/theme]
|
||||||
|
|
||||||
[/code]
|
[/code]
|
||||||
This will select the theme named "apw" and select the "passion" schema (theme variant).
|
This will select the theme named "suckerberg" and select the "passion" schema (theme variant). Alternatively it may be possible to use a condensed theme notation for this.
|
||||||
|
|
||||||
|
[code]
|
||||||
|
[theme]suckerberg:passion[/theme]
|
||||||
|
|
||||||
|
[/code]
|
||||||
|
|
||||||
|
The condensed notation isn't part of Comanche itself but is recognised by the $Projectname platform as a theme specifier.
|
||||||
|
|
||||||
[b]Regions[/b]
|
[b]Regions[/b]
|
||||||
Each region has a name, as noted above. You will specify the region of interest using a 'region' tag, which includes the name. Any content you wish placed in this region should be placed between the opening region tag and the closing tag.
|
Each region has a name, as noted above. You will specify the region of interest using a 'region' tag, which includes the name. Any content you wish placed in this region should be placed between the opening region tag and the closing tag.
|
||||||
@ -165,6 +171,41 @@ The 'comment' tag is used to delimit comments. These comments will not appear on
|
|||||||
|
|
||||||
[/code]
|
[/code]
|
||||||
|
|
||||||
|
[b]Conditional Execution[/b]
|
||||||
|
You can use an 'if' construct to make decisions. These are currently based on system configuration variable or the current observer.
|
||||||
|
|
||||||
|
[code]
|
||||||
|
[if $config.system.foo]
|
||||||
|
... the configuration variable system.foo evaluates to 'true'.
|
||||||
|
[else]
|
||||||
|
... the configuration variable system.foo evaluates to 'false'.
|
||||||
|
[/if]
|
||||||
|
|
||||||
|
[if $observer]
|
||||||
|
... this content will only be show to authenticated viewers
|
||||||
|
[/if]
|
||||||
|
|
||||||
|
[/code]
|
||||||
|
|
||||||
|
The 'else' clause is optional.
|
||||||
|
|
||||||
|
Several tests are supported besides boolean evaluation.
|
||||||
|
|
||||||
|
[code]
|
||||||
|
[if $config.system.foo == bar]
|
||||||
|
... the configuration variable system.foo is equal to the string 'bar'
|
||||||
|
[/if]
|
||||||
|
[if $config.system.foo != bar]
|
||||||
|
... the configuration variable system.foo is not equal to the string 'bar'
|
||||||
|
[/if]
|
||||||
|
[if $config.system.foo {} bar ]
|
||||||
|
... the configuration variable system.foo is a simple array containing a value 'bar'
|
||||||
|
[/if]
|
||||||
|
[if $config.system.foo {*} bar]
|
||||||
|
... the configuration variable system.foo is a simple array containing a key named 'bar'
|
||||||
|
[/if]
|
||||||
|
[/code]
|
||||||
|
|
||||||
[b]Complex Example[/b]
|
[b]Complex Example[/b]
|
||||||
[code]
|
[code]
|
||||||
[comment]use an existing page template which provides a banner region plus 3 columns beneath it[/comment]
|
[comment]use an existing page template which provides a banner region plus 3 columns beneath it[/comment]
|
||||||
|
Reference in New Issue
Block a user