Discussion:
[tw5] Syntax for setwidget
(too old to reply)
Mat
2018-08-06 11:02:12 UTC
Permalink
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
<https://tiddlywiki.com/prerelease/#SetWidget>)

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

<<foo>>

Thanx

<:-)
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e24cbec2-6b06-444b-84ed-0bca295c5fa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mat
2018-08-06 11:22:35 UTC
Permalink
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???


<:-)
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/15a94e49-efbf-4f6f-ad31-740ba8eeb43d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jed Carty
2018-08-06 11:23:17 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/f3d90959-4d26-47d7-a5f9-0a29eee8d599%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jed Carty
2018-08-06 11:34:11 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/7f1ee7c7-d9f9-49f2-966b-f14d2daebf1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mat
2018-08-06 13:51:13 UTC
Permalink
@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
<https://github.com/Jermolene/TiddlyWiki5/issues/3376>, in Jeremys post.


<:-)
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e500df80-b215-47ea-9f04-2f41092232f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...