Forums / Setup & design / getting text version of an XML Blocks
Damien Pobel
Tuesday 18 October 2005 3:08:07 am
I'm making a website with eZPublish 3.7 and I want to build a page which sums up all published news. So I want to display only the first 200 characters of each news. I've seen the shorten template operator (http://ez.no/doc/ez_publish/technical_manual/3_6/reference/template_operators/strings/shorten) but I 'm actually not able to retrieve the content of the news without any (xml or html) tags.Is there a way to get an XML Block as a plain text or a better way to retrieve just the beginning of it ?
Thanks for help.
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
Michael D.
Tuesday 18 October 2005 6:59:18 am
You can use $node.data_map.your_xml_block.content.output.output_text|strip_tags() to recieve a plain text version.
But you'll have to create a custom template operator named strip_tags first:http://ez.no/products/ez_publish_cms/documentation/development/extensions/template_operator
The function could look like this (including all the required stuff described in the above documentation page):
... case 'strip_tags': { $operatorValue = $this->strip_tags($operatorValue, $namedParameters['allowable_tags']); } break; ... function strip_tags($str, $allowable_tags) { return strip_tags($str, $allowable_tags); }
Mads Ovesen
Tuesday 18 October 2005 7:20:44 am
The strip_tags function is already defined i php. All you need to do follow the instructions from the above-mentioned link, and just add the line: PHPOperatorList[reverse]=strip_tagsto template.ini. Remember to clear to cache.
/m
Tuesday 18 October 2005 7:26:02 am
I thought that this method works only for PHP functions with one parameter as stated in the docs: http://ez.no/products/ez_publish_cms/documentation/development/kernel/custom_template_operators(Notes/Limitations)
Does this work for PHP functions with more than one parameters yet or does it work because the second paramter of strip_tags is optional?
Anyway, if it does, Mads way is surely the easier one.
Tuesday 18 October 2005 7:44:55 am
The method only works with functions that take one parameter, but as you mention the second parameter of strip_tags is optional. This must be the reason, why it works in this case. I have succesfully used the simple method.
Tuesday 18 October 2005 8:54:19 am
Good to know, this will save me some time in the future.Thank you for the info.
Now it's Damien's turn to say if this is what he was looking for. *g*
Friday 21 October 2005 2:02:15 am
thanks for answers !
I use the "PHPOperatorList" method as I need to remove all tag.Juste one precision if somebody needs to use this method, you have to write
$your_text|strip_tags()
and not
strip_tags($your_text)