
eZ publish content object attributes output rendering
In last tutorial have explained how to fetch eZ publish content objects with PHP. In this post I will show how to access eZ publish content objects attributes of all available datatypes. For testing PHP code we will re-use the same CLI script. This example you can re-use in your custom modules, cron jobs scripts, etc.
Thank you to Kristian Hole for his initial idea.
Here is edited and enhanced working code for rendering content objects attributes output:
#!/usr/bin/env php <?php include_once( 'lib/ezutils/classes/ezcli.php' ); include_once( 'kernel/classes/ezscript.php' ); $cli =& eZCLI::instance(); $script =& eZScript::instance( array( 'use-modules' => true ) ); $script->startup(); $options = $script->getOptions(); $script->initialize(); include_once ('lib/ezutils/classes/ezfunctionhandler.php'); include_once( 'kernel/common/template.php' ); $tpl = templateInit(); $node = eZFunctionHandler::execute( 'content','node', array( 'node_id' => 2) ); $object =& $node->object(); foreach( $object->contentObjectAttributes() as $contentObjectAttribute ) { $datatypeString = $contentObjectAttribute->attribute( 'data_type_string' ); $tpl->setVariable( 'attribute', $contentObjectAttribute ); $cli->output( $tpl->fetch( 'design:content/datatype/view/' . $datatypeString . '.tpl') ); } $script->shutdown(); ?>
The presented example uses the standard datatype templates only. It will not take into consideration override-rules you have in your override.ini(.append.php). In the case that you have such rules, you need to load the correct templates yourself.






