Forums / Setup & design / remove return carriage from XML output
Jean-Baptiste Crestot
Monday 09 May 2011 2:07:10 am
Hi all,
I'm new in the Exponential templating and I have a problem with a particular point!
I need to get the output of a XML bloc and send it to a javascript function, the problem is that javacript functions need to have their text arguments on the same line.
I use this method to get XML content :
data_map.myBlocXML.content.output.output_text
And when I add a image in the XML bloc, the output add some return carriage that make me this :
So it break my javascript code!
I looking for a solution to remove these return carriage from output.
Thank's for answer,
JB Crestot
Marko Žmak
Monday 09 May 2011 3:07:04 am
You should replace the newline character with an empty string of space. Since there's no string replace operator in eZP you'll have to use some extension that allows you to do it. For example wrap operator, which allows you to execute any PHP function. Or you can search on projects.ez.no for an extension that implements the string replace operator.
To eZ team: it's a real shame that eZP by default lacks such basic and essential operators for string manipulation.
-- Nothing is impossible. Not if you can imagine it! Hubert Farnsworth
Monday 09 May 2011 3:29:52 am
Oh god...
Thank you Marko for your reply. wrap operator seems good.
Quoc Huy Nguyen Dinh
Monday 09 May 2011 4:16:39 am
Alternatively you could do
{def $outputXML = $myObject.data_map.myBlocXML.content.output.output_text|explode("\n")|implode(" ")}
Not tested though...
Monday 09 May 2011 4:41:26 am
Thank's for answer, but it doesn't work. :(
Edit: actually I made a mistake, something else break my code but this code work properly!
Thank you a lot.
Monday 09 May 2011 8:08:48 am
Hum,
I know that I shouldn't ask my question in the same topic, but that's the same solution.
Now, my pb is that simple quote break my code, couldn't I do this :
{def $outputXML = $myObject.data_map.myBlocXML.content.output.output_text|explode("\n")|implode(" ")|explode(" ' ")|implode(" \' ")} (without spaces of course)
or
{$outputXML|explode(" ' ")|implode(" \' ")} (without spaces of course)
Tuesday 10 May 2011 3:21:00 am
Okey, I guess it's not possible to do two explode implode during the same time.
And for my second purpose, it was missing the set $outputXML = $outputXML|explo...)
But finaly, I don't used this method.
I used the addslashes from php (by adding PHPOperatorList[addslashes=addslashes] in template.ini) and making :
myObject.data_map.myBlocXML.content.output.output_text|explode("\n")|implode(" ")|addslashes()}
Thanks for your help.