Getting transclusion the whole table of content

335 views
Skip to first unread message

Andrej Korenić

unread,
Jul 12, 2018, 6:07:19 AM7/12/18
to tiddl...@googlegroups.com
I finally found that TW5 has really neat way of handling ToC entries, and I search macros and discussion topics to find whether it would be possible to transclude all of those tiddlers into one single tiddler?

Basically I am just using:

<div class="tc-table-of-contents">
<
<toc "Contents" sort[title]>>
</div>

and nested tags as example suggests.

I used the code from the topic about numbered headings in TW5:

<div class="nr">

{{H 1}}

{{H 1-1}}

</div>

so I can get the heading numbers if I transclude tiddlers one by one (by using their title and showing caption in ToC), however I cannot find how to automatize that process.

Many thanx

Andrej Korenić

unread,
Jul 12, 2018, 9:16:51 AM7/12/18
to TiddlyWiki
I guess that I would need to adapt ToC macro not to show only caption or title, but to transclude the content of every tiddler so some change in code like this is needed...

\define toc-caption()
<$set name="tv-wikilinks" value="no">
 
<$transclude field="caption">
   
<$view field="title"/>
 
</$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'><$view field='title'/></$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

\define toc(tag,sort:"",itemClassFilter:" ")
<<toc-body tag:"""$tag$""" sort:"""$sort$""" itemClassFilter:"""$itemClassFilter$""">>
\end


Mark S.

unread,
Jul 12, 2018, 12:39:17 PM7/12/18
to TiddlyWiki
There are multiple ways to interpret your request. Here's one:

\define toc-body(tag,sort:"",itemClassFilter,exclude,path)

 
<$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">

         
<$list filter="[all[current]toc-link[no]]" emptyMessage="<h1><$view field='title'></h1><$transclude mode='block'/>">
<h1><$view field="title"/></h1>            
<$transclude mode='block'/>

         
</$list>
          <$macrocall $name="toc-body" tag=<<item>> sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" exclude=<<excluded>> path=<<path>>/
>

     
</$set>
    </
$vars>
 
</$list>
\end

Put the macro definition at the top of your tiddler followed by your toc macro invocation, and it will give a "flattened" (no indents) version of the TOC with each title presented as an H1 header. This will number the header's using C Pa's stylesheet.

Be sure to make backups before trying this in case there are recursion errors.

HTH
-- Mark

Andrej Korenić

unread,
Jul 13, 2018, 5:06:14 AM7/13/18
to TiddlyWiki
Thank you Mark for the effort. It did something partially...

What I needed was to transclude all tiddlers that are connected to a root tag, in the similar manner as ToC works:

Chapters
Chapter 1
Chapter 2
Chapter 2.1

I managed to use TW5 macro to make ToC based on tags and ordered by means of the list field of the parent tag tiddler, but I am not able to crack what should I change to get all of these tiddlers transcluded in given order.

Thanx,
Andrej

Andrej Korenić

unread,
Jul 13, 2018, 5:28:54 AM7/13/18
to TiddlyWiki
I found an example at TW5 Magick by Stephan Hradek called Another TOC example  but I am still not good enough at TW5 scripting to understand fully how it works...

Basically your code from up above gets the list of tiddlers correctly and in right order. I just don't get it how to transclude them into one tiddler like Stephen's Another TOC example - Full Story shows. I don't need the titles of tiddlers, only content rendered appropriately.

Thanx again


Andrej Korenić

unread,
Jul 13, 2018, 6:25:10 AM7/13/18
to TiddlyWiki
Well, I got it working... I don't know how but here is the solution...

I created tiddler called Transclude chapters that was tagged with $:/tags/Macro. Code is this:

\define transclude_chapters(tag,sort:"",itemClassFilter,exclude,path)


 
<$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">


       
<$transclude mode='block'/>

         
<$macrocall $name="transclude_chapters" tag=<<item>> sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" exclude=<<excluded>> path=<<path>>/>

      </
$set>
   
</$vars>
  </
$list>
\end

So I just call it with the root tag:

<<transclude_chapters "Table of Contents">>

and that's it :)

TonyM

unread,
Jul 13, 2018, 9:58:37 PM7/13/18
to TiddlyWiki
Andrej,

Good work, 

I was about to reply with the basic "recursion" approach, where the macro calls itself, importantly from inside a list widget, so it is limited to the set of members in that lists filter. I think a lot of people leave this behaviour to toc macros when you can build it yourself once you understand the pattern.

That is the macro will work its way through all members of that hierarchical list, down branches to the leaves, once the leaf siblings are all listed it returns to the previous level....

In side the list other than calling the macro you can place anything you want to take place on every item in the hierarchy.  

Regards
Tony

The Islander

unread,
Mar 27, 2020, 1:15:19 PM3/27/20
to tiddl...@googlegroups.com
Hi @TonyM, could you clarify with some code explaining what you've said below?


I don't see the list filter affecting the output of the toc macro at all.

<$list filter="[all[current]has[caption]get[caption]] [all[current]!has[caption]get[title]] +[reverse[]]">
<div class="tc-table-of-contents">
<<toc-selective-expandable "TableOfContents">>
</div>
</$list>

TonyM

unread,
Mar 27, 2020, 4:42:56 PM3/27/20
to TiddlyWiki
The islander

I see in retrospect its confusing. I believe I was referring to a custom recursive function inside the list, I should not have placed the existing macro name there.

Perhaps start a new topic with what you after. I and others have learned a lot since then.

Regards
Tony

Reply all
Reply to author
Forward
0 new messages