Tuesday 18 May 2004 5:56:59 pm - 5 replies
Does anyone know any method (probably template operator) to remove HTML formatting from the string (attribute value). I would like to display ezXML field as normal plain text and now I can not see operator that is doing this.
Regards
Wednesday 19 May 2004 3:52:27 pm
This is not what I need. Wash only removes "bogus" characters (eq. replaces ® registered trademark with with &reg; that do not display corrextly at all). However I need operator to remove normal HTML tags, eq "<p>". If someone have one - I will be gratefull
Wednesday 19 May 2004 4:04:58 pm
In template.ini(.append.php)
add under
[PHP]
....
PHPOperatorList[striptags]=strip_tags
......
Then in your template use
$yourstring_with_xml|striptags
and catch the stripped output
A fuller example in the packt ez publish book available later this month
hth
-paul
Thursday 20 December 2007 6:26:02 am
Hi,
In case anyone needs it, here's a quick and dirty template-based method for stripping HTML tags from an XML field.
The code takes an article (intro) XML and strips out any "<" and ">" and the text in between.
{def $child_intro_raw=$child.data_map.intro.data_text}
{def $child_intro=""}
{def $split_string=$child_intro_raw|explode("<")}
{foreach $split_string as $this_string_part}
{def $sub_string=$this_string_part|explode(">")}
{set $child_intro=$child_intro|append($sub_string[1])}
{undef $sub_string}
{/foreach}
{* display result *}
<a title="{$child_intro}" href={$child.url_alias|ezurl}>{$child.name|wash()}</a>
It may fail if there are any < or > symbols in the text.
If you wanted to strip out a particular tag, it may be possible to change the first to explode function to something like, say, {def $split_string=$child_intro_raw|explode("<p"
}
You may find that there are blank lines before the basic text you actually want. To get rid of this, change the code above with the if condition shown below.
{foreach $split_string as $this_string_part}
{def $sub_string=$this_string_part|explode(">")}
{if ne($sub_string[1]|count_words(),0)}
{set $child_intro=$child_intro|append($sub_string[1])}
{/if}
{undef $sub_string}
{/foreach}
- Paul
Modified on Thursday 20 December 2007 7:12:39 am by Paul Wilson
Thursday 20 December 2007 9:15:55 am
Hi,
have a look at http://projects.ez.no/xmlwash it contains an operator that strips the tags (or only keep some, eg b and i...)
You must be logged in to post messages in this topic!