Ye olde way of making a button that does different things and looks different, depending on some state tiddler, is to use $reveal
. That can quickly add up to a lot of lines. Take e.g. the $:/core/ui/Buttons/timestamp
, here trimmed down to the basics for demonstration purposes:
<$reveal type="nomatch" state="$:/config/TimestampDisable" text="yes">
<$button class=<<tv-config-toolbar-class>>>
<$action-setfield $tiddler="$:/config/TimestampDisable" $value="yes"/>
{{$:/core/images/timestamp-on}}
</$button>
</$reveal>
<$reveal type="match" state="$:/config/TimestampDisable" text="yes">
<$button class=<<tv-config-toolbar-class>>>
<$action-setfield $tiddler="$:/config/TimestampDisable" $value="no"/>
{{$:/core/images/timestamp-off}}
</$button>
</$reveal>
The same can be done in three lines using inline filtering:
<$button class=<<tv-config-toolbar-class>> set="$:/config/TimestampDisable" setTo={{{ [{$:/config/TimestampDisable}match[yes]then[no]else[yes]] }}}>
<$transclude tiddler={{{ [{$:/config/TimestampDisable}match[yes]then[$:/core/images/timestamp-off]else[$:/core/images/timestamp-on]] }}} />
</$button>
Yeah, OK, the lines are a bit longer. But not so much. And yes, the $action-setfield
inside the $button
is discouraged anyway. If the condition was used in more places (e.g. button text), I’d probably define a variable and check that to shave some more bytes off.
I think the $reveal
is more readable, but not by much, and one cannot ignore the very concise alternative, no? I’m forgoing the whole button content near-duplication…
Have a nice day
Yaisog