Hello,
While all the tweakability of the checkbox widget is great, I still wanted something similar that would change the actual graphic of the box and toggle between a “view” and “edit” mode (thus the default values). So I put the following together using examples from tiddlywiki.com that I never would have figured out on my own:
\define toggleButton(tiddler:"target" field:"mode" offValue:"view" offImage:"""$:/core/images/edit-button""" onValue:"edit" onImage:"""$:/core/images/save-button""")
<$button class="tc-btn-invisible">
<$action-listops $tiddler="$tiddler$" $field="$field$" $subfilter="+[toggle[$onValue$],[$offValue$]]" />
Option 1
<$reveal type="nomatch" stateTitle="$tiddler$" stateField="$field$" text="$onValue$">{{$offImage$}}</$reveal>
<$reveal type="match" stateTitle="$tiddler$" stateField="$field$" text="$onValue$">{{$onImage$}}</$reveal>
Option 2:
{{{[[$tiddler$]get[$field$]match[$onValue$]then[$onImage$]else[$offImage$]]||transclude}}}
Option 3:
<$let buttonImage={{{[[$tiddler$]get[$field$]match[$onValue$]then[$onImage$]else[$offImage$]]}}}>
<$transclude tiddler=<<buttonImage>>/>
</$let>
</$button>
\end
My questions are:
Of these three options for displaying the icon image:
- Is one better in some way or are they all pretty much interchangable?
- The transcluded filter is a nice compact way to do things but necessitates another filter tiddler named “transclude” that just has
{{}}
in it. Is there a built in core template equivalent that I could re-purpose?$:/core/ui/ViewTemplate/body/default
seemed to be the closest but put things into block-mode and I would like to keep it inline. - Is there a way to tweak the filter such that you don’t need a template? I tried using
{$onImage}
rather than[$onImage$]
but it just burped up the SVG text as a link.
I settled on Option 3 as the one to use but I would like to hear thoughts from others and suggestions to make it more globally useful.
Thanks,
/Mike