major
minor
major
minor
HTML can be embedded in TLScript using {{{...}}}. Within this, script expressions can in turn be embedded using {`...}`, and the result of evaluating these expressions is output.
The Macro, Template, and Report attribute types use this HTML mode of TL-Script as an HTML template language with embedded expressions. The document is actually HTML, but it can contain TL-Script expressions enclosed in {`...}` within attributes or text content.
<div>
The answer is <b>{6 * 7}</b>.
</div>
As a result, the template document remains valid HTML and can also be edited in a browser (or WYSIWYG editor)—at least as long as the expressions are simple (and can be written as plain text).
However, if you want to generate dynamic HTML within the embedded script and switch back to HTML mode using {{{...}}} to do so, the entire document will either become completely unreadable—because you have to quote all < characters—or it will no longer be renderable as HTML:
<div>
My favorite numbers are:
</div>
<ul>
{
count(1,100).filter(x -> $x % 7 == 0).map(x ->
{{{
<li>{$x}</li>
}}}
)
}
</ul>
This document contains text between <ul> and the <li>...</li> pair and is therefore no longer valid HTML. To be able to store such scripts in normal HTML attributes, it would be better to mark up an embedded script using an HTML script tag:
<div>
My favorite numbers are:
</div>
<ul>
<script type="text/tlscript">
count(1,100).filter(x -> $x % 7 == 0).map(x ->
{{{
<li>{$x}</li>
}}}
)
</script>
</ul>
Although an HTML editor won’t automatically display the script’s content in the preview, at least the script can be edited in the editor’s source code view.
Test
- /com.top_logic.model.search/src/test/java/test/com/top_logic/model/search/expr/TestHtmlMacroExpansion-testEmbeddedScriptTag.script.html