On Monday, November 6, 2017 at 4:15:46 AM UTC-8, TonyM wrote:
>
> If I have a Global macro that sets;
> \define whikiname() MyWikiName
> Such that I can use <<whikiname>> any where to return the value
> "MyWikiName"
> Is there a way I can do something if the Current Tiddler has the same
> name, or the same name with a known suffix
>
> If ((!!title)) equals <<whikiname>> do
> This
> End
>
> If ((!!title)) Not Equals <<whikiname>>
> do This
> End
>
You can use the $reveal widget to render conditional content.
Normally, $reveal takes a "state", "type " and "text" params, and compares
a value *stored in the text field of a tiddler* (the state) against the
specified text value (which can be literal text, a variable, or a tiddler
field reference). The type param is either "match" or "nomatch" (i.e.,
"equals" or "not equals"). Thus, assuming that "SomeTiddler" contains the
state value, you can write conditional code like this:
<$reveal state="SomeTiddler" type="match" text={{!!title}}>
current tiddler's title matches content in SomeTiddler
</$reveal>
<$reveal state="SomeTiddler" type="nomatch" text={{!!title}}>
current tiddler's title does NOT match content in SomeTiddler
</$reveal>
Of course, it is not always convenient (or even possible) to use a state
tiddler all the time. Sometimes -- as in your requested use-case -- the
value to compare is stored in a variable (i.e., <<whikiname>>).
Fortunately, there is a variant usage of $reveal, that can compare ANY two
values, by using the "default" param, which is applied when no "state"
param is supplied. Thus:
<$reveal text={{!!title}} type="match" default=<<whikiname>>>
title matches the value of <<whikiname>>
</$reveal>
<$reveal text={{!!title}} type="nomatch" default=<<whikiname>>>
title does NOT match the value of <<whikiname>>
</$reveal>
Note that the value for the "default" param can be any valid reference, not
just a variable. Thus, it is possible to compare ANY two fields, from any
tiddler you want, like this:
<$reveal text={{!!title}} type="match" default={{!!otherfield}}>
title matches the value stored in "otherfield"
</$reveal>
<$reveal text={{!!title}} type="nomatch" default={{!!otherfield}}>
title does NOT match the value stored in "otherfield"
</$reveal>
You might also note that the default value could be a reference like
{{SomeTiddler!!text}}, which effectively reproduces the standard $reveal
usage. In other words, the following two code excerpts are equivalent:
<$reveal state="SomeTiddler" type="match" text={{!!title}}>...
and
<$reveal text={{!!title}} type="match" default={{SomeTiddler!!text}}
The default value can also be literal text, which allows you to check a
variable for an empty value, like this:
<$vars somevariable="foo">
<$reveal text=<<somevariable>> type="match" default="">
blank
</$reveal>
<$reveal text=<<somevariable>> type="nomatch" default="">
not blank
</$reveal>
</$vars>
Hopefully, the above is enough to address your particular use-case needs
or, at least, enough to point you in the right direction.
enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas" (tm)
InsideTiddlyWiki: The Missing Manuals
--
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 [email protected].
To post to this group, send email to [email protected].
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/5a92f465-a350-40a0-b9f7-fe0e36d8469b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.