Lukasz Serwatka - serwatka.net

Perfection + Vision +

ezxmltext: How to store and ouput your content?

One of many questions on ez.no forums is how to store and output data from ezxmltext datatype using PHP code. Here are some examples which you can use in your eZ publish scripts.

Input

Example with eZSimplifiedXMLInputParser

include_once ('lib/ezutils/classes/ezfunctionhandler.php');
// Fetch example node
$node = eZFunctionHandler::execute( 'content','node', array( 'node_id' => 2) );
$object =& $node->object();
 
include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinput.php' );
include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinputparser.php' );
include_once( 'kernel/classes/datatypes/ezxmltext/ezxmltexttype.php' );
 
// Some example content
$XMLContent = "<p>some text <b>this is bold text</b> some text <i>some text</i></p>";
 
$parser = new eZSimplifiedXMLInputParser( $object->attribute( 'id' ) );
$parser->setParseLineBreaks( true );
 
$document = $parser->process( $XMLContent );
 
// Create XML structure
$xmlString = eZXMLTextType::domString( $document );
 
// Loop through  contentobject attributes
foreach( $object->contentObjectAttributes() as $contentObjectAttribute )
{
    // Store only in  short_description attribute
    if ( $contentObjectAttribute->attribute( 'contentclass_attribute_identifier' ) == 'short_description' )
    {
        // Store XML structure in ezxmltext attribute
        $contentObjectAttribute->setAttribute( 'data_text', $xmlString );
        $contentObjectAttribute->store();
    }
}

Output

Example 1
include_once ('lib/ezutils/classes/ezfunctionhandler.php');
// Fetch example node
$node = eZFunctionHandler::execute( 'content','node', array( 'node_id' => 2) );
$object =& $node->object();
 
// Loop through  contentobject attributes
foreach( $object->contentObjectAttributes() as $contentObjectAttribute )
{
    // Get only content from short_description attribute
    if ( $contentObjectAttribute->attribute( 'contentclass_attribute_identifier' ) == 'short_description' )
    {
        include_once('kernel/classes/datatypes/ezxmltext/handlers/output/ezxhtmlxmloutput.php');
        // Get XML content from contentobject attribute
        $XMLContent = $contentObjectAttribute->attribute( 'data_text' );
        $outputHandler = new eZXHTMLXMLOutput( $XMLContent, false, $contentObjectAttribute );
        $htmlContent =& $outputHandler->outputText();
        echo $htmlContent;
    }
}
Example 2
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
 
// {def $node=fetch( 'content', 'node', hash( 'node_id', 2 ) )}
$node =& eZContentObjectTreeNode::fetch( 2 );
 
// {$node.object.data_map}
$object =& $node->object();
$dataMap =& $object->dataMap();
 
// {$node.object.data_map.short_description.content.output.output_text}
$shortDescription =& $dataMap['short_description']->content();
$shortDescriptionOutput =& $shortDescription->attribute('output');
$shortDescriptionOutputText = $shortDescriptionOutput->attribute('output_text');
 
echo $shortDescriptionOutputText;

See also blog post "eZ publish content object attributes output rendering" and learn how to access eZ publish content objects attributes of all available datatypes.

Trackbacks

No trackbacks.

Comments



Storing Data

When a user clicks on a link I would like to update a single integer attribute, to be used as a rating, where would I put the above input php? How would I make the link run that php? Is there a better way todo this?

Many Thanks... in advance

Thanks

Thaks. This is very useful Luke :-)

eZ publish CMS

eZ publish is a open source enterprise content management system and development framework with functionality for web publishing, intranets, e-commerce and more.

› read more

To sign-up for my Newsletter
Please enter your email address:
Silverlight support in eZ Publish

As Microsoft Silverlight technology is becoming increasingly popular, it will be supported in the upcoming eZ Publish 4.1 release. Sites using the Website Interface and eZ Flow will include a Silverlight class and the corresponding view templates. Simply upload .xap files (compressed Silverlight package) as attributes in Silverlight objects; when such an object is viewed by a site visitor, your Silverlight media is loaded in the web browser (provided that the visitor has the Silverlight browser plugin installed). This is similar to how eZ Publish already supports .swf files via the Flash class. More information will be available as the next eZ Publish release date approaches.

eZ Publish developer day in Warsaw, Poland - 15th April 2008

I happy to announce first eZ Publish developer day that will be held in Warsaw in Poland on 15th of April 2008. First time eZ goes to Poland ;) eZ Publish developer day is community-driven event and open for all attendees. Agenda will be settled at the event by the attendees. Some discussions will be in English.

Roadmap for eZ Publish 4.1 and 4.5

A roadmap for the next eZ Publish releases is now available. eZ Publish 4.1, the next major release, will include the new Online Editor, as was previously mentioned in Community Newsletter #1/2008. The new Online Editor will have various enhancements regarding usability and the user interface, and will support Internet Explorer 7 for Windows Vista. eZ Publish 4.1 is expected to be released in the first quarter of 2008.

Copyright © 2008 Łukasz Serwatka XHTML | CSS | Powered by eZ Systems AS eZ Publish ECMS™