3.7. Instructions
3.7.14. opt:literal
3.7.13. opt:insert
« Previous
3.7.15. opt:prolog
Next »

3.7.14. opt:literal

opt:literal instruction controls the parsing of XML CDATA sections with OPT. Normally, OPT compiles them according to their semantics: it moves them to the output, but without parsing their content. CDATA tags are moved, too. For template designer, such behavior is not always acceptable. Having the JavaScript code and some data do be put into it, we would like to escape part of that code not to be parsed by OPT, but at the same time, it will be decorated with a huge amount of <![CDATA[ and ]]> and the browser will not parse such result.

<script type="text/javascript">
<![CDATA[
    document.write('Hello my friend, do you need {$object} or ]]>{$object}<![CDATA[?');
]]>
</script>

In the example above, the output JS code is simply destroyed. Here it's a place for opt:literal. We can enclose our JS code inside it, and then the template CDATA sections will not be rewritten to the output. Instead, opt:literal will generate its own CDATA beginning and end that encloses the complete code:

<script type="text/javascript">
<opt:literal>
<![CDATA[
    document.write('Hello my friend, do you need {$object} or ]]>{$object}<![CDATA[?');
]]>
</opt:literal>
</script>

Result:

<script type="text/javascript">
<![CDATA[
    document.write('Hello my friend, do you need {$object} or sunglasses?');
]]>
</script>

However, opt:literal offers you more decorators. It can be used to generate dynamic HTML comments or simply to hide the existence of CDATA sections from the browser. The behavior may be chosen with the following attribute:

Name Type Required? Default Description
type ID No cdata What to display?

Allowed values are:

See also:

3.7.14. opt:literal
3.7. Instructions
« Previous
3.7.13. opt:insert
Next »
3.7.15. opt:prolog