mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-29 21:09:56 +00:00
b7562f0c7b
* Initial Commit * Update docs * Add support for elseif blocks * Another test * WIP * Change from `{%if%}` to `<%if%>` See discussion here - https://talk.tiddlywiki.org/t/proposed-if-widget/7882/64 * Don't use the widget body as the template if a list-empty widget is present See discussion here - https://github.com/Jermolene/TiddlyWiki5/pull/7710#issuecomment-1717193296 * List widget should search recursively for list-template and list-empty * Allow block mode content within an if/then/else clause * Update docs * Add from-version tag to docs
62 lines
1.9 KiB
Plaintext
62 lines
1.9 KiB
Plaintext
created: 20230901122740573
|
|
modified: 20230901123102263
|
|
tags: WikiText
|
|
title: Conditional Shortcut Syntax
|
|
type: text/vnd.tiddlywiki
|
|
|
|
<<.from-version "5.3.2">> 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).
|
|
|
|
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)
|
|
<% if [<animal>match[Elephant]] %>
|
|
It is an elephant
|
|
<% else %>
|
|
<% if [<animal>match[Giraffe]] %>
|
|
It is a giraffe
|
|
<% else %>
|
|
It is completely unknown
|
|
<% endif %>
|
|
<% endif %>
|
|
\end
|
|
|
|
<<test "Giraffe">>
|
|
|
|
<<test "Elephant">>
|
|
|
|
<<test "Antelope">>
|
|
'/>
|
|
|
|
Notes:
|
|
|
|
* 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
|
|
|