Folks, The 5.3.2 Prerelease now has a number of new features listed and one of these is quite different in form and possibly ease of use, that is the Conditional Shortcut Syntax.
- I have started this Topic to solicit initial observations and to encorage our broader community to have a look before these become part of the next version of tiddlywiki.
- Unless you are interested in a preview I suggest you ignore this for now and the users that do will help you come to terms with the new features once they understand themself.
For the inquisitive, please read on.
- When the pre-release becomes the next version we are bound to maintain backward compatibility, so its great to get it right in the first instance.
- If you have the time and an interest perhaps you can pick another change in the next release and start another topic.
- It is really helpful that users of different skills have a look and give us your impressions and experts a like to push the boundaries of new features.
- What you share now will also help development of the documentation.
For example this is documented here and the leading example is;
<% if [<animal>match[Elephant]] %>
It is an elephant
<% elseif [<animal>match[Giraffe]] %>
It is a giraffe
<% else %>
It is completely unknown
<% endif %>
- This is the first example of “naked filters”
- Only if and elseif are provided filters.
- They can be nested.
I took another example and moved the condition into a function demonstrating how when using functions we can make this into a plain language form.
\function .host-local-file() [{$:/info/url/protocol}match[file:]]
<% if [.host-local-file[]] %>
Loaded from a file URI
<% else %>
Not loaded from a file URI
<% endif %>
- Note here I am abandoning the filter for a function, that returns something or not
- I have tested the use of
<<local-tiddlywiki>>
and that also works.
Some thoughts and Questions as I start exploring this;
- Since this is Wiki text it should be valid in macros and Procedures, transclusions, fieldnames, and inside widgets, now even custom widgets.
- What impact could this have on the way we represent conditional statements?
- What are its strengths and weaknesses when compared to filters in other widgets such as the list widget?
- In other languages that provide if then else structures, are their any features you would like here?
- This almost looks like pseudo code, what other features could we have that support a complete set of pseudo code elements that represent actual code?
- Perhaps this will prove to be an elegat way to document filter examples and syntax?
- Since we can use “naked filters” how can we craft meaning full filters eg
[all[current]object-type[notes]]
- Perhaps we need a shortcut for current tiddler?
- eg
\function this() [all[current]]
and usethis[]
to set the current tiddler.- What other names or symbols could we use?
- I favor one I have used before the tilde, which tends to mean the root word in dictionaries here it means the current title/tiddler
- eg
\function ~() [all[current]]
so[~[]...
is equivalent to[all[current]...
or[<currentTiddler>...
- eg
Usage guidelines
- Perhaps there is an argument to use this approach when you just want the result of the filter to choose what to display, but not to use any value it creates?
- Although you can use the filter again eg
{{{ filter }}}
- Although you can use the filter again eg
- We often use the list widget as a condition but often we also use it to list multiple items, There is an argument that the if/(then)/else/endif is when we are not acting on a list “unless it is inside a list”.
Technical Questions;
- Would there be a way for us to reference the result of the filter to use in the content?
- Is there a way to use filters with multiple runs in them (Yes via a function?) but how abount inline.