Update docs

This commit is contained in:
Jeremy Ruston
2023-09-14 17:54:59 +01:00
parent 4a2a04f4c7
commit c392020152
@@ -4,9 +4,33 @@ tags: WikiText
title: Conditional Shortcut Syntax
type: text/vnd.tiddlywiki
The conditional shortcut syntax provides a convenient way to express if-then-else logic within WikiText. It evaluates a filter and considers the condition to be true if there is at least one result.
The conditional shortcut syntax provides a convenient way to express if-then-else logic within WikiText. It evaluates a filter and considers the condition to be true if there is at least one result (regardless of the value of that result).
For example:
A simple example:
<$macrocall $name='wikitext-example-without-html'
src='<% if [{$:/$:/info/url/protocol}match[file:]] %>
Loaded from a file URI
<% else %>
Not loaded from a file URI
<% endif %>
'/>
One or more `<% elseif %>` clauses may be included before the `<% else %>` clause:
<$macrocall $name='wikitext-example-without-html'
src='<% if [{$:/$:/info/url/protocol}match[file:]] %>
Loaded from a file URI
<% elseif [{$:/$:/info/url/protocol}match[https:]] %>
Loaded from an HTTPS URI
<% elseif [{$:/$:/info/url/protocol}match[http:]] %>
Loaded from an HTTP URI
<% else %>
Loaded from an unknown protocol
<% endif %>
'/>
The conditional shortcut syntax can be nested:
<$macrocall $name='wikitext-example-without-html'
src='\procedure test(animal)
@@ -28,8 +52,10 @@ src='\procedure test(animal)
<<test "Antelope">>
'/>
Within an "if" or "elseif" block, the variable `condition` contains the value of the first result of evaluating the filter condition.
Notes:
Note that widgets and HTML elements must be within a single conditional block; it is not possible to start an element in one conditional block and end it in another.
* Clauses are parsed in inline mode by default. Force block mode parsing by following the opening `<% if %>`, `<% elseif %>` or `<% else %>` with two line breaks
* Within an "if" or "elseif" clause, the variable `condition` contains the value of the first result of evaluating the filter condition
* Widgets and HTML elements must be within a single conditional clause; it is not possible to start an element in one conditional clause and end it in another
* The conditional shortcut syntax cannot contain pragmas such as procedure definitions
Note that the conditional shortcut syntax cannot contain pragmas such as procedure definitions.