BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
856 stars 130 forks source link

Support template script defined in CDATA tag #376

Closed longgt closed 7 years ago

longgt commented 7 years ago

In template script, if condition have more than 1 (conjunction is &&) and included in JSF page, when JSF page is loaded, an exception will be throw.

JSF does not accept special characters such as && in script tag without CDATA.

In case of adding template script in CDATA, JsView does not render template properly. For example

<script type="text/javascript">
//<![CDATA[
           {{if a && b}}
               c
           {{/if}}
 //]]>
</script>

Here is my temporary solution for now Encode special characters by using url encode before including it in template script

<script type="text/javascript">
//<![CDATA[
           {{if a &amp;&amp; b}}
               c
           {{/if}}
 //]]>
</script>

It'll be quite cool if JsView supports template with content defined in CDATA.

BorisMoore commented 7 years ago

You should be able to do the analogous trick to what is done in javascript blocks (putting the CDATA open and close (XML) tag in JavaScript comments // xxx) - so in this scenario you instead use JsRender comment tags wrapping the CDATA tags:

<script type="text/javascript">{{!--<![CDATA[--}} {{if a && b}} c {{/if}} {{!--//]]>--}}</script>

BorisMoore commented 7 years ago

Can you let me know if this works for you? Thanks.

longgt commented 7 years ago

It's work perfectly. Thanks.

BorisMoore commented 7 years ago

Ah good. Thanks. Closing issue...