Share » Forums » Developer » Execute template code from with...

Execute template code from with object attribute

Execute template code from with object attribute

Wednesday 07 September 2005 8:25:19 pm - 2 replies

Modified on Thursday 06 October 2005 2:01:12 pm by James Robertson

Author Message

James Robertson

Wednesday 21 September 2005 4:09:56 pm

I guess one solution might be to modify the eZ template 'include' function so that it can be passed template code as a string instead of having to point to a template file.

What URI schemas does 'include' support. I guess if it support HTTP you could pass it the template code this way - instead of from the file-system.

Anyone have any ideas?

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;
}

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu