Forums / Developer / How to render an XML Block into XHTML (PHP script)
Hakim Bouras
Wednesday 27 May 2009 11:58:38 pm
Hi,
I am building a light newsletter feature. The body of the newsletter is contained in an XML Block attribute of an eZ object.
In my PHP client script, how can I render this XML Block into XHTML (used in the emails body) ?
<i>(I need somehow the equivalent of the template operator attribute_view_gui attribute=xml_block_body)</i>
Also would you have an idea how to convert the XHTML to plain text ?
ThanksHakim
Damien Pobel
Wednesday 03 June 2009 3:20:52 am
Hi Hakim,
To get the XHTML output of an XML Block attribute, you can write something like :
$dataMap = $node->attribute( 'data_map' ); $output = $dataMap['your_attribute_identifier']->attribute( 'content' )->attribute( 'output' ); $xhtml = $ouput->attribute( 'output_text' );
And to convert the XHTML to plain text, you can use the strip_tags PHP function [1]
[1] http://php.net/strip_tags
Damien Planet eZ Publish.fr : http://www.planet-ezpublish.fr Certification : http://auth.ez.no/certification/verify/372448 Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish
Thursday 04 June 2009 4:38:24 am
Hi Damien,
Thanks a lot for your help.
Actually I had to change a small thing to make it work : to use the method "outputText()" instead of the attribute "output" (but this is maybe due to the fact I am using a version 4.1).
$output = $dataMap['your_attribute_identifier']->attribute( 'content')->attribute( 'output' ); $xhtml = $output->outputText();
Cheers,Hakim
André R.
Thursday 04 June 2009 6:02:24 am
Hakim: what class is $output? ( call "var_dump($output);" for instance)
$ouput->attribute( 'output_text' ); should have worked, as it uses outputText() in eZXMLOutputHandler, but if you have another output handler for some reason, then it might not work.
eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription @: http://twitter.com/andrerom
Friday 05 June 2009 4:50:45 am
I retried the code provided by Damien, and in fact it is working fine. I probably missed something the first time I tried.
Thanks again for your help, and sorry for the burden,Hakim