Reveal if current tiddler is tagged

385 views
Skip to first unread message

Allen Ormond

unread,
Jun 29, 2018, 12:50:11 PM6/29/18
to TiddlyWiki
Is there a way to reveal or transclude only if the current tiddler has a certain tag?

Dummy code below:
if current_tiddler_tags include "foo"
  display "bar"
end

I'm sure there's a way to do this, I just haven't wrapped my head completely around TW yet.

Thanks!

Mark S.

unread,
Jun 29, 2018, 1:21:45 PM6/29/18
to TiddlyWiki
Usually I would use a list widget for this tag-based hiding:


<$list filter="[all[current]tag[Test]]">
MY STUFF GOES HERE
</$list>

The all[current] filter operator restricts the domain to the current tiddler. Replace "MY STUFF GOES HERE" with whatever you want.

HTH
-- Mark

Allen Ormond

unread,
Jun 29, 2018, 1:39:22 PM6/29/18
to TiddlyWiki
Perfect! Thanks Mark.

TonyM

unread,
Jun 29, 2018, 9:15:10 PM6/29/18
to TiddlyWiki
Mark,

I would think it better to add variable="null" to the list widget since we know at best the value inside the list will be our targeted tag.

By using a variable the stuff will remain relavant to the current tiddler such as field references etc

Regards
Tony

Mark S.

unread,
Jun 29, 2018, 9:23:15 PM6/29/18
to TiddlyWiki
Right. Good point.

-- Mark

Marcio Augusto

unread,
Jun 30, 2018, 4:04:50 PM6/30/18
to TiddlyWiki
Hi Tony,

I didn't follow here. How setting variable helps, if the default is currentTiddler?

Regards,
Marcio.

Mark S.

unread,
Jun 30, 2018, 4:43:58 PM6/30/18
to TiddlyWiki
If you set a variable inside the listwdiget, it no longer resets "currentTiddler" to the value of the filtered tiddler. Instead the named variable is set to te value of the filtered tiddler.
This allows currentTiddler to stay the same as outside the listwidget loop.

-- Mark

TonyM

unread,
Jun 30, 2018, 10:26:34 PM6/30/18
to TiddlyWiki
Marcio,

Yes, you are correct in this case it does not matter because the test is against the current tiddler and will only list the current tiddler inside the list, as in these two examples that have identical outputs

Read on to learn why I suggest it as a rule, otherwise ignore it.

The following are identical with or without the variable set because the result is only the current tiddler
<$list filter="[all[current]tag[Test]]">
Current tiddler title = {{!!title}}<br>
or <
<currentTiddler>><br>
Other field value = {{!!test-field}}
<br>
</$list>


<$list filter="[all[current]tag[Test]]" variable="null">
Current tiddler title = {{!!title}}
<br>
or <
<currentTiddler>><br>
Other field value = {{!!test-field}}
<br>
</$list>

The difference comes when the filter results in more than one answer, which is not your use case

For example when two tiddlers are tagged with Test are the results, with this changed filter,

<$list filter="[tag[Test]]">
<h3>Tiddler {{!!title}}</h3>
"<
<currentTiddler>>" is the each tiddler title
<h4>~~The calling tiddler details~~</h4>
Current tiddler title = {{!!title}}
<br>
or <
<currentTiddler>><br>
Other field value = {{!!test-field}}
<br>
</$list>


---


<$list filter="[tag[Test]]" variable="tiddlertitle">
<h3>Tiddler <<tiddlertitle>></h3>
"<
<tiddlertitle>>" is the each tiddler title
<h4>The calling tiddler details</h4>
Current tiddler title = {{!!title}}
<br>
or <
<currentTiddler>><br>
Other field value = {{!!test-field}}
<br>
</$list>

In  the first case you no longer have simple access to the calling tiddlers details, they are exchanged for the filtered tiddlers (ones tagged with Test)

In the second case you retain the calling tiddlers values inside the list.

To access other fields in this second case you can use the view widget
<$view tiddler=<<tiddlertitle>> field="test-field"/>

However in many applications you do not need to reference the <<tiddlertitle>> or test-field so I add the variable, but call it null, and never use <<null>>
eg
<$list filter="[tag[Test]]" variable="null">
blah blah

This becomes even more important if you have nested lists multiples levels deep, because it allows you to continue referencing the calling tiddlers title and fields all the way down. Which in most cases is exactly what we want to do.

So as a rule I use the variable=null or another variable name if I may want access to the containing tiddlers details available inside the list widget or nested widgets.

And in your case it makes no difference, so no harm doing it?

<$list filter="[all[current]tag[Test]]" variable="null">

MY STUFF GOES HERE
</$list>


Rehards
Tony

Marcio Augusto

unread,
Jun 30, 2018, 11:08:48 PM6/30/18
to tiddl...@googlegroups.com
Hino Tony,
Thanks for the detailed explanation. I was just seeing one side of the coin, did not realize the use case of preserving the calling tiddler title inside the list, or the nesting of lists.
Regards,
Marcio.

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/1DmYe8JA8Nw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@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/31c65657-4fe7-4db1-8592-1aa02bf495ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

TonyM

unread,
Jul 1, 2018, 12:06:03 AM7/1/18
to TiddlyWiki
Sure, Yes I ran down a rabbit hole you did not need to go down, Sorry.

But you do get to learn more about the rabbit warren.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages