Forums / Setup & design / getting text version of an XML Blocks

getting text version of an XML Blocks

Author Message

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_tags
to template.ini. Remember to clear to cache.

/m

Michael D.

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.

Mads Ovesen

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.

/m

Michael D.

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*

Damien Pobel

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)

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

eZ debug

Timing: Jan 18 2025 22:36:41
Script start
Timing: Jan 18 2025 22:36:41
Module start 'content'
Timing: Jan 18 2025 22:36:41
Module end 'content'
Timing: Jan 18 2025 22:36:41
Script end

Main resources:

Total runtime0.0207 sec
Peak memory usage4,096.0000 KB
Database Queries4

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 587.8281180.8281
Module start 'content' 0.00730.0059 768.6563102.0234
Module end 'content' 0.01320.0074 870.679778.7031
Script end 0.0206  949.3828 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002411.5270120.0002
Check MTime0.00105.0453120.0001
Mysql Total
Database connection0.00105.056810.0010
Mysqli_queries0.002512.137340.0006
Looping result0.00000.096920.0000
Template Total0.007033.910.0070
Template load0.00104.828410.0010
Template processing0.006029.048710.0060
Override
Cache load0.00063.082810.0006
General
dbfile0.00188.5192100.0002
String conversion0.00000.030030.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs