Syntax for setwidget

50 views
Skip to first unread message

Mat

unread,
Aug 6, 2018, 7:02:12 AM8/6/18
to TiddlyWiki
This seems like a bug to me... but it's such a basic use case that it then should have been discovered ages ago... so I'd better ask before issuing a report:

How can I make this return "no value" when there is no argument. Currently it returns "value" regardless or argument or no argument.

(direct link to SetWidget docs)

\define foo(bar)
<$set name="myVariable" filter="$bar$" value="value" emptyValue="no value">
<$text text=<<myVariable>>/>
</
$set>
\end

<<foo>>

Thanx

<:-)


Mat

unread,
Aug 6, 2018, 7:22:35 AM8/6/18
to TiddlyWiki
Well, I cracked it;

\define foo(bar)
<$set name="myVariable" filter="$bar$ +[first[]]" value="value" emptyValue="no value">

<$text text=<<myVariable>>/>
</
$set>
\end

<<foo>>


...still, I don't understand why merely "$bar$" without any incoming argument can't be interpreted as empty???


<:-)

Jed Carty

unread,
Aug 6, 2018, 7:23:17 AM8/6/18
to TiddlyWiki
The docs say that it uses the value attribute if there is no filter given, so the behaviour is consistent with the documentation.

It does seem a bit weird but from a coding point of view I can see why it is this way.

Jed Carty

unread,
Aug 6, 2018, 7:34:11 AM8/6/18
to TiddlyWiki
The quick version is that in javascript you can say if(filter) {use filter code} else {use non-filter code}, if filter is an empty string it is evaluated as false which is the same as if there is no filter. So it isn't the existence of the "filter=" part that makes it change to the filter based behaviour, it is "if(filter)" evaluating as true that does it.

You can explicitly check for filter being an empty string, but that may modify other behaviour that could cause other problems.

Mat

unread,
Aug 6, 2018, 9:51:14 AM8/6/18
to TiddlyWiki
@Jed, thanks for input on it. 

----------

For anyone curious, I needed it to make a little quick reveal type macro because IMO the RevealWidget syntax is just too messy. 
The syntax for qreveal (=quick reveal) is:

<<qreveal label content>>


the "label" is optional, but if you are using more than one qreveal in a tiddler then you need labels for them

So in practice it might look like

<<qreveal "
So this is some content that will be revealed.
"
>>


Here's the macro:


title: macro/qreveal
tags
: $:/tags/Macro
text
:

\define qreveal(label, content)
<$set name=label filter="""$content$ +[first[]]""" emptyValue="nolabel" value="$label$">
<$set name=content filter="""$content$""" emptyValue="""$label$""" value="""$content$""">

<$reveal type="nomatch" text="show"
    state
={{{ [[$(currentTiddler)$]addprefix[$:/state/qreveal/]addsuffix[/]addsuffix<label>] }}}>

<$button setTo="show"
    set={{{ [[$(currentTiddler)$]addprefix[$:/state/qreveal/]addsuffix[/]addsuffix<label>] }}}>
   <<label>> ▷
</
$button>

</$reveal>
<$reveal type="match" text="show"
    state={{{ [[$(currentTiddler)$]addprefix[$:/state/qreveal/]addsuffix[/]addsuffix<label>] }}}>

<$button setTo="hide"
    set={{{ [[$(currentTiddler)$]addprefix[$:/state/qreveal/]addsuffix[/]addsuffix<label>] }}}>
   <<label>> ▽
</
$button>

<<content>>

</$reveal>
</
$set>
</$set>
\end



P.S The reason for the complex way to set state names is given here, in Jeremys post.


<:-)
Reply all
Reply to author
Forward
0 new messages