Change from Template to ViewTemplate

111 views
Skip to first unread message

MidnightLightning

unread,
Mar 21, 2019, 12:41:51 PM3/21/19
to TiddlyWikiDev
I created a Tiddler intended to be used as a Template for Transclusion, that shows a list of pages tagged with the current tiddler, with a header on the list:

Pages tagged with <$macrocall $name="tag-pill-body" tag=<<currentTiddler>> icon={{!!icon}} colour={{!!color}} palette={{$:/palette}} element-tag="""$button""" element-attributes="""tag='span'"""/>:
<ul><$list filter="[tag<currentTiddler>]">
<li><$link><$view field="title" /></$link></li>
</$list></ul>

That works well enough if I add in "{{||Tagged Pages List}}" on the tiddlers that are used as tags, but what I'd like is to put in the logic "If any tiddlers use this tiddler as a tag, then show this block of text". I think adding a tiddler as a ViewTemplate would allow this, but what I'm struggling with is that header above the list. On pages that have no tiddlers that use it as a tag, I don't want that header to show.

I see the CountWidget as a way to get a "how many tiddlers are tagged with this one" (<$count filter="[tag<currentTiddler>]" />), but how to do the "if ... then" logic within the template, to not show anything if the count is zero? Is this one where I'd be best defining my own Widget to handle that?

TonyM

unread,
Mar 22, 2019, 10:50:09 PM3/22/19
to TiddlyWikiDev
MidnightLightning

Partial answer for you, but FYI the standard google groups is appropriate for this kind of question and you may get a faster response there.

Rather than count the tags $list the tags with limit[1] and the content of the list widget will only show if there are more than one tag.

[tag<currentTiddler>limit[1]]

You could use emptyMessage if you wanted.

In other circumstances (except variables at present) you can use the View widget, as The content of the <$view> widget is displayed if the field or property is missing or empty.

Regards
Tony

MidnightLightning

unread,
Mar 25, 2019, 9:25:24 AM3/25/19
to TiddlyWikiDev
Thanks, that got me on the right track for an answer!

Using the [tag<currentTiddler>limit[1]]] filter as an outer $list works, though it resets the currentTiddler variable to the first tiddler that's tagged with the original tiddler. So, I ended up doing this:

A global Macro (in case I want to use it elsewhere):

\define listTagged(tagName)
<$set name="t" value=<<__tagName__>>><$list filter="[title<t>]">
<$count filter="[tag<t>]" /> Pages tagged with <$macrocall $name="tag-pill-body" tag=<<currentTiddler>> icon={{!!icon}} colour={{!!color}} palette={{$:/palette}} element-tag="""$button""" element-attributes="""tag='span'"""/>:
<ul><$list filter="[tag<t>]">

<li><$link><$view field="title" /></$link></li>
</$list></ul>
</$list>
</
$set>
\end


And then a ViewTemplate to use it:

<$set name="t" value=<<currentTiddler>>>
<$list filter="[tag
<currentTiddler>limit[1]]">
<hr />
<$macrocall $name="listTagged" tagName=<
<t>> />
</$list>
</$set>


The trick is I used a $set call to save the first currentTiddler value to a separate variable (t) for use later in the logic.

TonyM

unread,
Mar 27, 2019, 10:15:08 PM3/27/19
to TiddlyWikiDev
I am glad that got you to the destination you wanted.

You may find using `$(currentTiddler)$` in a macro to access the value from whence it was called, as a way to access a prior value of `<<currentTiddler>>` rather than use the $set widget

Regards
Tony

Mohammad

unread,
Mar 28, 2019, 12:24:47 AM3/28/19
to TiddlyWikiDev
Why dont put all of them in one tiddler?

MidnightLightning

unread,
Mar 28, 2019, 11:59:28 AM3/28/19
to TiddlyWikiDev
I didn't put them all in one tiddler since I want to use pieces of it elsewhere; on tag pages, I want it automatically added as a suffix after the body of the tiddler. But on other tiddlers, I may want to talk about some different tags and include a list about them (e.g. "RPG characters have skills and feats. <$macrocall $name="listTagged" tagName="skills" /> <$macrocall $name="listTagged" tagName="feats" /> Pick two skills and one feat to start.").
Reply all
Reply to author
Forward
0 new messages