-
Notifications
You must be signed in to change notification settings - Fork 0
Conditions
Parts of a snippet can be produced by condition. Condition elements can be used anywhere within a snippet.
There are two kinds of condition statements:
a) Simple condition
<ps:if test="'{{foo}}' === 'bar'">
<!-- elements if condition holds true -->
</ps:if>
The content is produced, if the test holds true.
b) Complex choice (if-then-else/select)
<ps:choose mode="strict">
<ps:if test="'{{foo}}' === 'bar'">
<!-- elements -->
</ps:if>
<ps:else>
<!-- elements -->
</ps:else>
</ps:choose>
A <ps:choose>
may contain numerous <ps:if>
-tests and one <ps:else>
that will be produced if none of the ifs holds true.
There are two modes of processing the choice:
-
mode="strict"
(default) only the first matching<ps:if>
will be produced, then the choice ends -
mode="lax"
all matching<ps:if>
will be produced.
A test
-expression will be evaluated as a string. Meaning, you can only access any of placeholders properties, but not execute methods.
<!-- this will not work --> <ps:if test="typeof {{myObject}} === 'object'">Provide a placeholder
typeof_myObject = typeof myObject
(which provides an evaluable string) instead or test on'{{myObject.constructor.name}}'
.
Keep in mind to enclose string values in quotes.
The prefix ps:
used in XML code is the recommended tag prefix for elements of the pageSnippet-namespace:
<ps:pagesnippets xmlns:ps="https://github.com/suppenhuhn79/pagesnippets">