TiddlyWiki5
TiddlyWiki5 copied to clipboard
[Idea] It is proposed to create if/then/else convenience functions also be usable with list and reveal
It is proposed to create if/then/else convenience functions also be usable with list and reveal
A main goal should be, that the new functions are "simpler" than a similar construction with the reveal-widget or the list-widget
From: https://github.com/Jermolene/TiddlyWiki5/issues/6854
Indeed, but such a thing belongs in the core, or its own plugin, and wouldn't be appropriate for this docs plugin.
So should we create a PR using the condition plugin code?
As far as I can remember, the widgets have to follow a specific syntax pattern to work as intended. eg: JS syntax used to describe the problem
// the following syntax is OK
if (var === true) {
// do something
} else {
// do something else
}
// The following syntax in _wrong_
if (var === ture) {
// do something
}
var x = y;
else {
// do something else
}
In JS it's clear, that we get a syntax error.
But the same problem happens if we use "faulty syntax" in wikitext, which would be a new behaviour.
<!-- this does _not_ work -->
<$list filter="false">
<!-- do something -->
</list>
<br>
<$else> <!-- do something --> </$else>
This is a difference in behaviour of widgets, since the else-widget needs to "find" it's related sibling. ... I'm only 90% sure that I got the problem right. ... The plugins where created in 2017 ...
Thanks @pmario.
The condition plugin uses lateral dependencies between widgets (eg the <$else>
widget being a sibling of the associated <$list>
widget) which is not currently supported by the core; the existing core code rests on the assumption that a widget can be refreshed without affecting its siblings, just its children. Under the circumstances, the condition plugin does a great job of getting things working. But, if we were going to support lateral dependencies between widgets then there's a lot more that I'd want to do, such as heading counters, which would mean refactoring things more thoroughly.
There is an alternative to the lateral dependencies. For example:
<$if condition="...">
<$then>
...
</$then>
<$else>
...
</$else>
</$if>
Also worth to see this post and discussion by Jeremy https://talk.tiddlywiki.org/t/switch-case-construct/2234/13
From https://talk.tiddlywiki.org/t/switch-case-construct/2234/13
To clarify, I do not think that we need new widgets for if/then/else or switch/case; as TW_Tones has shown, the required logic can be performed with the list widget. I am interested in exploring new wikitext syntax that acts a shortcut for those widgets.
As a simple example:
\if [<currentTiddler>match[yes]]
{{Foo}}
\else
{{Bar}}
\endif
Or:
\switch [<currentTiddler>]
\case "something"
{{Foo}}
\case "else"
{{Bar}}
\endswitch
I did update the OP, with a main goal -- simplicity ...
I think, if the new construction is as complex as using "reveal" or "list" it doesn't make sense to create them.
<!-- this does work -->
<$list filter="false">
<!-- do something -->
</list>
<br>
<$else> <!-- do something --> </$else>
That doesn't work, it will produce:
$else widget must follow $if, $else-if, $reveal or $list.
I use these a lot, even so, I prefer @Jermolene's <$if><$then>... construct even though it would present me with a massive rewrite.
That doesn't work, it will produce:
Sorry ... The text in front of the example was right. but the example itself was a "copy paste error" . Fixed it in the post
close this one because it will be implemented in v5.3.2