James Robertson
|
Wednesday 07 September 2005 8:25:19 pm
I would like to be able to execute a piece of eZ publish template code from within an object's attribute content? (ie. Perhaps something a bit like JavaScript eval() function.) For example: I have Text-block attribute that stored a fragment of XHTML. This fragment is displayed without washing. However, I would like to be able to insert a piece of eZ publish template code within the XHTML and have it execute prior to display.
I imagine, within the template, this might look like: {$node.data_map.xhtml|eval()}
|
James Robertson
|
Thursday 18 May 2006 3:24:55 pm
Solution supplied by eZ systems [thanks Kristion] for eZ publish version 3.6.4. It can be added as a 'template operator' extension [good luck working out how to do that ;-]:
/*
* WARNING:
* - This function works directly towards the template system,
* and might not be compatible with new versions of eZ publish.
* - The evaluated code will run in interpreted mode which can behave
(sligtly)
* different from compiled code, and is slower.
* - By using fetches and templatecode in content object attributes you can
* make a system which is very hard to maintain!
*
* This code should ONLY be used by professionals who understands what they
are doing
*/
function ezeval( $templateText )
{
include_once( 'kernel/common/template.php' );
include_once( 'lib/eztemplate/classes/eztemplate.php' );
$tpl =& templateInit();
$root = array( EZ_TEMPLATE_NODE_ROOT, false );
$resourceData = array( 'resource' => 'design', 'template-filename' =>
'eval_code' );
$rootNamespace = '';
$output = '';
$tpl->parse( $templateText, $root, $rootNamespace, $resourceData );
$tpl->process( $root, $output, '', '' );
return $output;
}
|