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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 08:04:15
Script start
Timing: Jan 31 2025 08:04:15
Module start 'layout'
Timing: Jan 31 2025 08:04:15
Module start 'content'
Timing: Jan 31 2025 08:04:16
Module end 'content'
Timing: Jan 31 2025 08:04:16
Script end

Main resources:

Total runtime1.3484 sec
Peak memory usage4,096.0000 KB
Database Queries71

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 588.2500151.2266
Module start 'layout' 0.00580.0027 739.476636.6797
Module start 'content' 0.00851.3389 776.15631,015.3203
Module end 'content' 1.34730.0010 1,791.476615.8281
Script end 1.3483  1,807.3047 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.3096160.0003
Check MTime0.00180.1353160.0001
Mysql Total
Database connection0.00070.054410.0007
Mysqli_queries1.242592.1509710.0175
Looping result0.00110.0790690.0000
Template Total1.307597.020.6538
Template load0.00290.211920.0014
Template processing1.304696.756020.6523
Template load and register function0.00190.139710.0019
states
state_id_array0.00120.091610.0012
state_identifier_array0.00150.114120.0008
Override
Cache load0.00240.1758390.0001
Sytem overhead
Fetch class attribute can translate value0.00120.091430.0004
Fetch class attribute name0.00380.280480.0005
XML
Image XML parsing0.02591.921630.0086
class_abstraction
Instantiating content class attribute0.00000.001690.0000
General
dbfile0.02722.0205160.0017
String conversion0.00000.000540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 30
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs