Pill template on ToC

75 views
Skip to first unread message

George ZP

unread,
Aug 10, 2018, 6:58:17 AM8/10/18
to TiddlyWiki

Hello everyone!

I'm relatively new to TW. I want to create a ToC for my tags.

I have created a Tiddler with the content
 
<div class="tc-table-of-contents">
<
<toc "tag tree" "is[tag]sort[title]">>
</div>

where `tag tree` is the tag tree root and `is[tag]` is used to populate the tree with only tags, not "leaf" tiddlers with content.

I want to display the ToC items as tag pills, most likely using the $:/core/ui/TagTemplate template.
My problem is that I don't know how to apply a template to each automatatic ToC item.

Any ideas?
Thanks

Mark S.

unread,
Aug 10, 2018, 10:28:15 AM8/10/18
to TiddlyWiki
 Unfortunately, you'll need to hack the TOC macro code a bit. Assuming that you only want this behavior in one tiddler, it's not too hard. Put this at the top of your tiddler:

\define toc-caption()
<$set name="tv-wikilinks" value="no">
 
<$transclude field="caption">
   
{{||$:/core/ui/TagTemplate}}
 
</$transclude>
</
$set>
\end

\define toc-body(tag,sort:"",itemClassFilter,exclude,path)
<ol class="tc-toc">
 
<$list filter="""[all[shadows+tiddlers]tag[$tag$]!has[draft.of]$sort$] -[[$tag$]] $exclude$""">
   
<$vars item=<<currentTiddler>> path="""$path$/$tag$""" excluded="""$exclude$ -[[$tag$]]""">
     
<$set name="toc-item-class" filter="""$itemClassFilter$""" emptyValue="toc-item" value="toc-item-selected">
       
<li class=<<toc-item-class>>>
         
<$list filter="[all[current]toc-link[no]]" emptyMessage="<$link><$view field='caption'>{{||$:/core/ui/TagTemplate}}</$view></$link>">
           
<<toc-caption>>
         
</$list>
          <$macrocall $name="toc-body" tag=<<item>> sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" exclude=<<excluded>> path=<<path>>/
>
       
</li>
      </
$set>
   
</$vars>
  </
$list>
</ol>
\end

Now the output will show up as buttons. This code slightly modifies two of the supporting macros of the TOC macro system (toc-caption and toc-body).  You can look at the code and see where the tag pill template was applied.

HTH
-- Mark


George ZP

unread,
Aug 10, 2018, 10:34:19 AM8/10/18
to TiddlyWiki
Mark,

Thank you for your reply.
While the formatting works, the on-click tag behaviour (showing the tagged Tiddlers) doesn't work.

Is this intentional, accidental or a shortcoming of your approach?

Mark S.

unread,
Aug 10, 2018, 10:40:21 AM8/10/18
to TiddlyWiki
# 3. Plus a little of the others.

Change the emptyMessage attribute to emptyMessage="{{||$:/core/ui/TagTemplate}}"

But you may not like the bold text it now uses to display the related tags.

-- Mark

George ZP

unread,
Aug 10, 2018, 10:43:08 AM8/10/18
to TiddlyWiki
Seems to work fine here (see attached photo). Thanks a bunch!
Reply all
Reply to author
Forward
0 new messages