How to wash an xmltext to populate an input field ?

Author Message

Xavier Dutoit

Wednesday 10 May 2006 9:42:47 am

Hi all, washing day today for me ;)

I want to use the content of an xmltext field to populate an input field.

eg <input type="hidden" value=" Things that come from a xml field">

I did try to use the (undocumented) wash(javascript) like that:

<input type="hidden"
  name="powercontent_intro_ContentObjectAttribute_data_text_pcattributeid"
  value='{$node.object.data_map.intro.content.output.output_text|wash(javascript)}' />

At least it solves the " let's go" problem (ie it doesn't stop the input value after the ' . However, it does replace the " by a \047 that isn't what is expected.

Are you aware of a wash thing that I could use for that ?

On a related problem: how do you use the xmlfield to populate a title tag ?

eg <a href="{$node.url_alias}" title='{$node.object.data_map.intro.content.output.output_text|strip_tags|wash(javascript)}' />

The result is not that good either.

Many thanks for your inputs and suggestions.

X+

http://www.sydesy.com

Kristof Coomans

Wednesday 10 May 2006 10:25:59 am

Hi Xavier

I don't know about a suitable washing operator to do this, but if it doesn't exist yet then maybe we can create our own? As I see it, I would just traverse the dom tree and append all text nodes to each other.

Didn't know there was a strip_tags operator either. Is it documented somewhere?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Łukasz Serwatka

Wednesday 10 May 2006 10:38:01 am

@Kristof
You can define it in template.ini.append.php

[PHP]
# A list with php functions and their equivelant template operator names
# Giving the operators a different name from the PHP functions
# are recommended, that way you ensure that all operators follow
# the same naming guidelines. It also means that you can change the
# php function later on without doing template changes.
PHPOperatorList[striptags]=strip_tags

Where value is name of PHP function.

@Xavier:

In many cases $content|wash is sufficient. Have you tried?

EDIT:
On community home page links to last forum topics uses:

{...content|wash|shorten( 400 )}

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Xavier Dutoit

Wednesday 10 May 2006 10:52:37 am

@Lukasz

Ok, I put " (double quote) instead of single onces and wash without additionnal parameter and it seems to work (so far).

<input type="hidden"
name="powercontent_intro_ContentObjectAttribute_data_text_pcattributeid"
value="{$node.object.data_map.intro.content.output.output_text|wash()}" />

Thanks for the help !

@Kristof,

I use it to populate attributes with powercontent. Works great !

@Who wants to listen.

The strip_tag operator is really mandatory in quite a lot of cases, even if it is far to be perfect. For instance, you can't use the shorten operator without it on a xmltext (otherwise, you're going to have your text cut between two tags with quite funny result).

Still don't get why it isn't standard in ez. Who should we beg/bribe/beat with a stick so it's included in the default ?

X+

http://www.sydesy.com

Xavier Dutoit

Wednesday 10 May 2006 10:57:26 am

@Lukasz

{...content|wash|shorten( 400 )}

I did remember having used it and it didn't make it. Can't remember now what was the pb. Does it works with all the tags ?

I had to do

{...content|strip_tags|wash|shorten( 400 )}

EDIT:

Looking at the code that was problematic, I shorten it first and then wash (I know, that's stupid). I'm going to give the wash only option.

X+

http://www.sydesy.com

Łukasz Serwatka

Wednesday 10 May 2006 11:09:24 am

Yes, you are right Xavier. Forum uses text filed so no tags in output by default (as long as user will include something), on ezxml filed you need to use striptags other way you will have xhtml tags in the output.

e.g

{$node.object.data_map.short_description.content.output.output_text|striptags|wash|shorten( 400 )}

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Xavier Dutoit

Wednesday 10 May 2006 11:12:39 am

@Lukasz,

Is the wash|shorten(lenght) used as well in the content/new ?

In that case, I see the problem:

It truncates after the first paragraph (or so it seems),

As quite a few post start with, <p>Hi</p> or <p>@Someone</p> it doesn't give a very usefull title, even so that would be possible to put more chars and stay under lenght.

I think it was why I strip_taged the content first.

X+

http://www.sydesy.com

Łukasz Serwatka

Wednesday 10 May 2006 11:15:23 am

I guess you use Firefox which does not understand new lines in title. Under Opera and IE works fine.

EDIT:
See comments here:
http://ez.no/community/blog/small_forum_update

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Xavier Dutoit

Thursday 11 May 2006 1:40:42 am

Indeed I use firefox.

I think I'll stick to strip_tags for now, until FF changes its behaviour.

Thanks,

X+

http://www.sydesy.com

Paul Forsyth

Thursday 11 May 2006 1:57:46 am

In the past i've used this tool to get cross-platform support:

http://www.walterzorn.com/tooltip/tooltip_e.htm

As its is js there is some overhead but it depends on what you need to do.

Paul

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