Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Can't create an XML with javscript inside using smarty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
juanjico
Smarty n00b


Joined: 03 Aug 2015
Posts: 1

PostPosted: Mon Aug 03, 2015 7:30 pm    Post subject: Can't create an XML with javscript inside using smarty Reply with quote

Hi!

I have this template:

Code:
<?xml version="1.0" encoding="utf-8"?>
<item>
        <Description><![CDATA[{$description}]]></Description>
</item>


$description contains HTML code with Javascript and CSS. Note the CDATA block in the XML to avoid parse that code.

Code:
$description = '
<p>This is just a test</p>
<script type="text/javascript">
alert('a');
</script>


When I assign the variable to the template and parse it, this is the result:

Code:
<?xml version="1.0" encoding="utf-8"?>
<item>
        <Description><![CDATA[<p>This is just a test</p>
<script type="text/javascript">/* <![CDATA[ */;alert('a');/* ]]> */</script> ]]></Description>
</item>


For some reason, smarty is adding a new CDATA to the javascript code, but taking in care that is to be used in XML, this is ilegal because two CDATA can't be nested. This XML don't validate.

Is there a way to avoid smarty add the CDATA and leave the javascript code intact ?

Thanks!
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Aug 03, 2015 9:26 pm    Post subject: Reply with quote

Smarty itself does not add anything to the output.

I suspect that it's already in the $description variable var_dump() it or set
$smarty->debugging = true; to check the assigned values of all template variables.

or

Did you enable some default modifier?
Check if {$description nofilter} will change anything.

or

Have you loaded an output filter which may do it.

Note: when you modify default modifier or filter settings you must force a recompile manually.
Best is to disable caching and set $smarty->force_compile = true while experimenting.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP