Easily show the contents of a variable, field, tiddler or text reference

Folks, I just thought I would share yet another helpful use of a function, as while designing tiddlywiki solutions it is helpful to;

Easily show the contents of a variable, field, tiddler or text reference

Place this in a tiddler with the $:/tags/Global tag or similar.

\function show(input) [<input>] [[=]]  [all[current]get<input>!is[blank]addsuffix[ⓕ, ]] [<input>getvariable[]!is[blank]addsuffix[ⓥ, ]] [<input>has[title]get[text]!is[blank]addsuffix[ⓣ, ]] [list<input>addprefix["]addsuffix["ⓡ, ]] +[join[]]

An wherever needed use <<show "what">>

The “what” can be any of the following;

  • a fieldname (on the current tiddler) ⓕ indicator
  • a variable name myvar ⓥ indicator
  • a tiddler title (will retrieve the content) good for config values etc… ⓣ indicator
  • a text reference such as tiddlername!!fieldname ⓡ (text reference) indicator for one or more values found.

Examples;

<<show storyTiddler>> 
<<show description>> 
<<show "$:/config/design-mode">> 
<<show "$:/StoryList!!list">>

Feedback and suggestions welcome

  • What other tricks and values could we return?
  • Shall we make the whole thing show/hide according to a parameter?
  • Is a widget for this any better or worse?
2 Likes

I ask myself, “does it need/can it make use of/ content?” If yes, it’s a widget.

Thats interesting;

I have recently observed the key difference between macros which can be used in wikitext, setting variables and in filters and widgets, is as a rule a widget is at the end of the process, that is it results are displayed and you can do no more with it, although it may show buttons etc… which do perform functions you just can’t use a widget as a variable, a macro you can.

However the above works nicely and there is not much value to setting its output to a variable (perhaps I will make a macro for this?)

However in keeping with the widget perspective I was already onto one that makes use of the ability to pass arbitrary Parmeter names with all sorts of ways to determine the value, when using widgets. So any thing you can turn into a parameter value you can view the result.

  • Note this widget has a default condition that only displays if $:/config/design-mode=yes.
\widget $show.params()
<$parameters condition="[{$:/config/design-mode}match[yes]]" list-all="yes" $params="@params">
<$setmultiplevariables $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>]">
<$list filter=<<condition>> variable=~>
   <$list filter="[<list-all>match[yes]]" variable=~>
   <$list filter="[<@params>jsonindexes[]] -[[condition]] -[[list-all]]" variable=parameter>
      <$text text=<<parameter>>/> = <$text text={{{ [<parameter>getvariable[]] }}}/>, 
   </$list>
   </$list>
   <$slot $name="ts-raw"/>
</$list>
</$setmultiplevariables>
</$parameters>
<!-- 
notes: The parameter can be any name that helps explain the value of the parameter.
Using filtered transclusions `{{{ filter }}}` or Substituted Attribute Values (using backticks) only return the first value by default.
Use `+[join[]]` or `+[format:title[cases[]join[ ]]` as needed
The condition defaults to `[{$:/config/design-mode}match[yes]]`
The content of the widget can contain wikitext and tiddlytwiki script that makes use of the variables generated from the parameter names.
If the list-all parameter is not yes (default), then the parameter/values will not be listed.
-->
\end $show.params

for example

;show.params

# <$show.params system-object={{!!system-object}}/>
# <$show.params system-object={{!!system-object}} condition="true"/>
# <$show.params tag-table-of-contrents=`${ [tag[TableOfContents]join[, ]] }$`/>

<hr>

<$show.params system-object={{!!system-object}} test="CodaCoder" >
Hi, <$text text=<<test>>/> system-object=<<system-object>>
</$show.params>
  • note any number of parameter values can be used

The following just determines the value in the same way as the show macro but only returns the value if you want to use/assign it elsewhere.

  • Which is only possible with macros unless you use wikify (not recomended)
\function value(input) [all[current]get<input>!is[blank]] [<input>getvariable[]!is[blank]] [<input>has[title]get[text]!is[blank]] [list<input>format:titlelist[]join[ ]] +[join[]]  :else[<input>]
  • Edited to pass the input if no value found.
1 Like