Show tag list only when grandchildren exist

124 views
Skip to first unread message

Stuart Amor

unread,
Jul 24, 2018, 2:10:41 PM7/24/18
to TiddlyWiki
I am looking for a way of returning a list of all the tiddlers that are tagged with the current tiddler title. However I would like to omit all tiddlers that are not themselves subsequently tagged.

Let me try to give you an example... if I have three tiddlers X, Y and Z. Within the parent tiddler X, I would like to return a list containing its child Y, provided Y is tagged with X AND Z is tagged with Y (ie X has a grandchild). However, if there were no tiddlers tagged with Y, then Y would not appear in the listing within X.

Does that make sense?

Diego Mesa

unread,
Jul 24, 2018, 3:21:38 PM7/24/18
to TiddlyWiki
Hey Stuart,

This code seems to work for me:

<$list filter="[all[current]tagging[]]" variable="child">

    <$list filter="[tag
<child>]" variable="grandchild">

        <
<child>> has grandchild <<grandchild>>

    </$list>

</$list>

You can test it on https://tiddlywiki.com/ by making 4 tiddlers:
  • titled X, with the content above
  • titled Y tagged with X
  • titled Z tagged with Y
  • titled Q tagged with X
Best,
Diego

Stuart Amor

unread,
Aug 2, 2018, 6:35:40 AM8/2/18
to TiddlyWiki
Thank you Diego, that has certainly put me on the correct path!  If I wanted to take this to the next stage, how could I change the output so that it would be presented as a outline structure:

  • Y
    • Z1
    • Z2
  • Q
    • P1
    • P2

Stuart Amor

unread,
Aug 3, 2018, 11:20:00 AM8/3/18
to TiddlyWiki
Its been awhile since I have used TW5 and its coming back to me slowly...  I have currently got down to the following code:

\define tagtable(Tag)
<$list filter="[tag[$Tag$]]" variable="Parent">
<$list filter="[tag<Parent>sort[]]" variable="Child">         
<$list filter="[tag<Child>sort[]]" variable="GrandChild">
<ul>
      <li><$link to=<<Parent>>><<Parent>></$link></li>
      <ul>
      <li><$link to=<<Child>>><<Child>></$link></li>
           <ul>
           <li><$link to=<<GrandChild>>><<GrandChild>></$link></li>
           </ul>
      </ul>
</ul>
</$list></$list></$list>
\end

<$macrocall $name="tagtable" Tag='X'/>


I have two problems with this, firstly I am not sure how I can pass the [all[current]tagging[]] via a macrocall - its not the end of the world if I can't, but I have had this situation quite a bit so would nice to be able to learn how it can be done if possible.

I have a bit of a dilemma as this code returns:

  • X
    • Y
      • Z1
  • X
    • Y
      • Z2

I would like X and Y to be able to group the Z values and only appear once.  I can see how this problem occurs, but can figure out a way of avoiding this problem without reintroducing the Parent's Children that don't have GrandChildren into the report. 

Mark S.

unread,
Aug 3, 2018, 12:45:16 PM8/3/18
to TiddlyWiki
Something like this may result in the kind of spacing you want and pre-detect grandchildren. Perhaps you don't even want the top-level to show if there are no grand children?

The <$list filter="[tag<Parent>limit[1]]"> listwidget here is used to detect if there are grandchildren. It's limited to 1 instance, since you don't want to multiply grandchildren by grandchildren.



\define tagtable(Tag)

<ul>
<li><$link to="""$Tag$""">$Tag$</$link></li>
<ul>


<$list filter="[tag[$Tag$]]" variable="Parent">
<$list filter="[tag<Parent>limit[1]]">
     
<li><$link to=<<Parent>>><<Parent>></$link></li>
     
<ul>
<$list filter="[tag
<Parent>sort[]]" variable="Child">        
     
<li><$link to=<<Child>>><<Child>></$link></li>
     
<ul>
<$list filter="[tag
<Child>sort[]]" variable="GrandChild">
           
<li><$link to=<<GrandChild>>><<GrandChild>></$link></li>
</$list>
</ul></$list></ul></$list></$list></ul></ul>
\end

<$macrocall $name="tagtable" Tag={{!!title}} />



Good luck!
-- Mark
Reply all
Reply to author
Forward
0 new messages