I'm finding this quite useful:
Here's the modified function:
<cms:set example = 'CouchCMS is great' />
<cms:show example case = 'upper' /> will display "COUCHCMS IS GREAT"
<cms:show example case = 'lower' /> will display "couchcms is great"
Here's the modified function:
- Code: Select all
function show( $params, $node ){
global $FUNCS, $CTX;
if( count($node->children) ) {die("ERROR: Tag \"".$node->name."\" is a self closing tag");}
extract( $FUNCS->get_named_vars(
array( 'var'=>'', /*placeholder*/
'scope'=>'',
'as_json'=>'0',
'case'=>'',
),
$params)
);
$value = $params[0]['rhs'];
$scope = strtolower( trim($scope) );
$as_json = ( $as_json==1 ) ? 1 : 0;
$case = strtolower( trim($case) );
// If scope set and first param is a variable, return variable only from the specified scope scope.
if( $scope != '' && $node->attributes[0]['value_type']==K_VAL_TYPE_VARIABLE ){
if( $scope!='1' && $scope!='2' && $scope!='global' && $scope!='local' ){
die("ERROR: Tag \"".$node->name."\" has unknown scope '" . $scope. "'. Only 'global (2)' or 'local (1)' are valid.");
}
$scope = ( $scope=='global' || $scope=='2' ) ? 2 : 1;
$value = $CTX->get( $node->attributes[0]['value'], $scope );
}
if( $case == 'upper' ){ $value = strtoupper( $value );}
if( $case == 'lower' ){ $value = strtolower( $value );}
if( $as_json && is_array($value) ){ $value = $FUNCS->json_encode( $value ); }
return $value;
}