XML Mode in MPTS
In XML mode, any valid XML file can be used as an MPTS template. However, MPTS extends standard XML with additional features for dynamic content generation.
Text Content
You can use expressions to insert dynamic text into your template. Expressions are enclosed in double curly braces ``.
Example:
<h1></h1>
<p></p>
Expressions can also be more complex:
All content rendered using `` is XSS-safe, preventing HTML injection.
For more details about expressions, see the Expressions document.
Element Attributes
All attribute values are treated as expressions. If the value is wrapped in quotes ("
or '
), it is treated as a string literal.
Example:
<div class="2+2" title=2+2/>
This will produce:
<div class="2+2" title="4"></div>
For more complex expressions, use parentheses:
<div class=(condition ? 'class-true' : 'class-false')/>
Embedding HTML/XML
You can embed raw HTML/XML using the << >>
syntax with variables containing HTML/XML code.
Example:
<<htmlContent>>
If the variable htmlContent
contains <span>Text</span>
, it will be rendered as HTML.
Warning: Ensure that the content is safe to prevent XSS vulnerabilities and injection attacs.
Control Structures
MPTS supports control structures like :if
, :else-if
, :else
, :loop
, and :foreach
for dynamic rendering.
Example:
<:if condition=(isVisible)>
<div>Visible</div>
</:if>
<:else>
<div>Hidden</div>
</:else>
Loop example:
<:loop count=5>
<li>Item</li>
</:loop>
Foreach example:
<:foreach collection=items item=item key=index>
<div>: </div>
</:foreach>
Comments
You can add comments using the XML comment syntax:
<!-- This is a comment -->
Notes
- All expressions must be syntactically correct.
- Expressions are evaluated in the context of the current data.
- MPTS templates are designed to be safe and prevent code injection.