Show toc-selective-expandable in tagged tiddlers

418 views
Skip to first unread message

Balázs Slemmer

unread,
Jan 28, 2020, 6:36:59 AM1/28/20
to TiddlyWiki
Hi!

I would like to show toc-selective-expandable after the contents of every tiddler that is tagged for example 'with-toc'. The root of the table of contents should be the current tiddler. I have tried many approaches (using macros, template tiddlers, etc.), but none of them seems to work. More precisely, they work when the root of the table of contents is a static, hard-coded tiddler title, but stop working when I try to use the title of the current tiddler. Can this be achieved? If so, how? Or is it not possible?

Thanks!

bimlas

unread,
Jan 28, 2020, 7:03:28 AM1/28/20
to TiddlyWiki
Üdv a klubban! :D

Create a tiddler of any name and add a $:/tags/ViewTemplate tag with the following content:

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

 
<h3>Contents</h3>

 
<div class="tc-table-of-contents">
    <$macrocall $name="toc-selective-expandable" tag=<
<currentTiddler>>/>
 
</div>

</$list>

I don't know exactly what code you were trying to try, but these are the most likely errors:

  • The 'list' widget overwrites the 'currentTiddler' variable with the current element of the filter result, so you might want to specify 'variable = "null"' if you use it just to check the value of a condition.
  • If you tried the "<<toc-selective-expandable tag:<<currentTiddler>> >>" format, the problem was with the syntax: you cannot use a macro in a macro call, you have to use "macrocall" widget.

bimlas

unread,
Jan 28, 2020, 7:05:03 AM1/28/20
to TiddlyWiki
Sorry, forgot to mention: you have to replace TableOfContents in the code above with "with-toc".

Balázs Slemmer

unread,
Jan 28, 2020, 7:51:48 AM1/28/20
to TiddlyWiki
Üdv! :)

I have probably messed up the syntax somewhere because I have also tried using the macrocall widget. Nevertheless it works now, so thanks! :)

For posterity's sake, here is my version of the above:

<$list filter="[all[current]tag[with-toc]]" variable="null">
  <$set name="sectionTitle" value={{!!contents_title}} emptyValue="Projects">
   
<h3><<sectionTitle>></h3>
  </$set>

 
<div class="tc-table-of-contents">

    <$macrocall $name="toc-selective-expandable" tag=<
<currentTiddler>>/>
 
</div>
</$list>

I wanted to be able to override the title of the TOC section from the individual tiddlers, if the default does not make sense there. I don't know if this is best way to do it, but it works :D

Mohammad

unread,
Jan 28, 2020, 1:50:19 PM1/28/20
to TiddlyWiki
Added to TW-Scripts

TonyM

unread,
Jan 28, 2020, 6:34:35 PM1/28/20
to TiddlyWiki
Folks,

I have another approach, test this on TiddlyWiki.com

Create a tiddler containing this and tag with $:/tags/ViewTemplate
\define default-toc-here()
   
<h4>Optional TOC here</h4>
<$list filter="[tag<currentTiddler>limit[1]]" emptyMessage="/
/nothing tagged with <<currentTiddler>>//" variable=nul >

   
<$macrocall $name="toc-selective-expandable" tag=<<currentTiddler>> >
</$list>
\end
<$list filter="[all[current]has:field[toc-here]]" variable=nul>
    <$list filter="[all[current]get[toc-here]]" variable=toc-tiddler emptyMessage=<<default-toc-here>> >
             <h4>Optional TOC <<toc-tiddler>></
h4>
             
<$macrocall $name="toc-selective-expandable" tag=<<toc-tiddler>> >
   
</$list>
</
$list>

  • Nothing will happen right away.
  • Now add the field toc-here to any tiddler and it will provide a toc based on the current tiddler. Use new here to add items to its toc
  • If however you give that field a value of tiddlername eg HelloThere then the tiddlername will be used as the root of the TOC
Advantages of this approach
  • No additional tag use
  • Ability to reference other parts of a TOC

I can see some useful enhancements, but do consider my approach as a "Code Pattern"

Regards
Tony

Julio Peña

unread,
Jan 28, 2020, 6:50:25 PM1/28/20
to TiddlyWiki
Hello Tony and all,

Wow, I can definitely see the use cases for this.
Thanks for sharing Tony :)

Cheers,
Julio

Mohammad

unread,
Jan 28, 2020, 11:11:15 PM1/28/20
to TiddlyWiki
Added to TW-Scripts

Mohammad

unread,
Jan 28, 2020, 11:15:52 PM1/28/20
to TiddlyWiki
Hi Tony,

How one can set the order of elements added to a tiddler through ViewTemplates?

The below script when is used with https://tiddlywiki.com/prerelease/ causes to have the TOC
at most bottom of tiddler and the Comment tool above TOC, but I think TOC should be appeared before Comment element

--Mohammad


On Wednesday, January 29, 2020 at 3:04:35 AM UTC+3:30, TonyM wrote:

Eric Shulman

unread,
Jan 29, 2020, 1:46:45 AM1/29/20
to TiddlyWiki
On Tuesday, January 28, 2020 at 8:15:52 PM UTC-8, Mohammad wrote:
How one can set the order of elements added to a tiddler through ViewTemplates?

You can define a "list-before" or "list-after" field on a tiddler to indicate the name of the other tiddler to precede or follow the current one.

You can also define a "list" field in a tiddler named "$:/tags/ViewTemplate" to control the order of all tiddlers tagged with $:/tags/ViewTemplate


-e

Mat

unread,
Jan 29, 2020, 1:52:37 AM1/29/20
to TiddlyWiki
Mohammad wrote:
Hi Tony,

How one can set the order of elements added to a tiddler through ViewTemplates?

You just click on the tag named $:/tags/ViewTempalte (in any tiddler!) to get the dropdown of all such viewtemplates. Therein you drag and drop to globally reorder them. 

<:-)

HC Haase

unread,
Jan 29, 2020, 4:04:31 AM1/29/20
to tiddl...@googlegroups.com
I plan to soon add a filter option to my TOC generic plugin.


onsdag den 29. januar 2020 kl. 00.34.35 UTC+1 skrev TonyM:
Folks,

I have another approach, test this on TiddlyWiki.com

Create a tiddler containing this and tag with $:/tags/ViewTemplate
\define default-toc-here()
   
<h4>Optional TOC here</h4>
<$list filter="[tag<currentTiddler>limit[1]]" emptyMessage="/
/nothing tagged with <<currentTiddler>>//" variable=nul >
   
<$macrocall $name="toc-selective-expandable" tag=<<currentTiddler>> >
</$list>
\end
<$list filter="[all[current]has:field[toc-here]]" variable=nul>
    <$list filter="[all[current]get[toc-here]]" variable=toc-tiddler emptyMessage=<<default-toc-here>> >
             <h4>Optional TOC <<toc-tiddler>></
h4>
             
<$macrocall $name="toc-selective-expandable" tag=<<toc-tiddler>> >
   
</$list>
</
$list>

  • Nothing will happen right away.
  • Now add the field toc-here to any tiddler and it will provide a toc based on the current tiddler. Use new here to add items to its toc
  • If however you give that field a value of tiddlername eg HelloThere then the tiddlername will be used as the root of the TOC
Advantages of this approach
  • No additional tag use
  • Ability to reference other parts of a TOC

This is a cool. I will see how to put that in the TOC generic plugin.

I can see some useful enhancements, but do consider my approach as a "Code Pattern"

what does Code Pattern mean?

TonyM

unread,
Jan 29, 2020, 5:48:57 AM1/29/20
to TiddlyWiki
HC

A Code Pattern is like one of those reciplies like sponge cake, it describes the underlying recipe which you can improvise on top of to create a strawberry sponge cake, a birthday cake like a clock, a fresh strawberry and cream sponge cake, a lemon passion fruit sponge cake. They are all fundamentally the same thing.

Code patterns are usually easy to reuse models that you can then customise, rather than a specific example for a specific purpose. They are all fundamentally the same thing.

Much easier to remember a hundred code patterns than a thousand specific cases.

FYI: As in my reply to Mohammad, I have built a button to toggle a field on any tiddler, to assist with my default toc above but now I am trying to generalize it so a new button can be created with little effort in future.

Regards
Tony

TonyM

unread,
Jan 29, 2020, 5:52:43 AM1/29/20
to TiddlyWiki
Mohammad,

Eric and Mats answers are what I use too, If I had shared a tiddler rather than in my reply, it would normally have a list-before or list-after field in it, if it belongs somewhere specifically, otherwise it placement is something I decide.

The Quick and easy way is drag and drop on the $:/tags/ViewTemplate tag pill, also easy to create with `<<tag "$:/tags/ViewTemplate">>`

Regards
Tony

Mohammad

unread,
Jan 29, 2020, 8:30:31 AM1/29/20
to TiddlyWiki
Thank you all!

So, when distributing a viewTemplate one can set the order!

--Mohammad

TonyM

unread,
Jan 29, 2020, 6:54:24 PM1/29/20
to TiddlyWiki
With list-before and list after yes.

Choose wisely so if others do the same it remains valid.

I tend to list before or after the body
Or after the subtitle

Tony

Reply all
Reply to author
Forward
0 new messages