[TW5] Question about TOCs, trees and hierarchies using fields

630 views
Skip to first unread message

Matthew Petty

unread,
May 4, 2015, 10:12:32 AM5/4/15
to tiddl...@googlegroups.com
I've been searching around and trying various old options, but I can't seem to find exactly what I need, so I'm asking directly. Is there a way to have an expandable tree generated, like the TOC example here: http://tiddlywiki.com/#TableOfContents

But I don't want to have to specify which tiddlers should appear in the TOC. I would like to do it by specifying a root tiddler, and then all the child tiddlers would have a field called "parent", which would point to the root tiddler.

In this way, you could have multiple levels, with each pointing to the relevant parent:

* Root (no parent)
   
* Level 1 (parent="Root")
        * Level 2 (parent="Level 1")

Then later on I could add another tiddler "New", give it the parent "Root", and the TOC would appear like this:
* Root (no parent)
    * Level 1 (parent="Root")
        * Level 2 (parent="Level 1")
    * New (parent="Root")

So the macro call would be:

<<TOCtree root="Root">>

The advantage of using the field like that is that I would only need to add the field to a tiddler, and the TOC would update.

Also, by specifying the root of the tree in the macro call, I could just show branches instead of the whole thing.

Is this possible? Has it been done?

Eric Shulman

unread,
May 4, 2015, 12:31:18 PM5/4/15
to tiddl...@googlegroups.com
The functionality you describe is almost *exactly* what the core TOC macro provides... except that it uses *tags* instead of a *custom field* ("parent") to define the hierarchy.  Simply tag a tiddler with the title of it's parent.  Provide the "root tag" in the <<toc>> macro, and all the rest happens auto-magically: starting from the root tag, it lists all tiddlers with that tag, and then recursively lists all tiddlers tagged with those tiddler titles, etc.

One advantage of using tags instead of a "parent" field is that you can have the same tiddler appear in more than one part of your tree, simply by tagging it with multiple tiddler names.  This can be useful for adding "reference" pages to various sections (e.g., a list of definitions could be tagged "Appendix", but also tagged with individual pages where those definitions are used, so that they are available for quick reference directly from those pages.

Note: the default core <<toc>> macro generates a fully-expanded tree.  The core also provides some variants of <<toc>>... to show a closed tree with "click to expand", use <<toc-selective-expandable>>.  Also, to get the same styles as the sidebar, wrap the macro with a "tc-table-of-contents" CSS class, like this:

@@.tc-table-of-contents <<toc-selective-expandable RootTagHere>>@@

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...

Jed Carty

unread,
May 4, 2015, 1:43:04 PM5/4/15
to tiddl...@googlegroups.com
In the tiddler you linked to the list field sets the order the entries appear in, it doesn't set which entries appear. So tagging something TableOfContents will put it in the table of contents at the first level, and trading something HelloThere will put it in the table of contents as a child of HelloThere.

I have a bit about them here http://inmysocks.tiddlyspot.com/#Creating%20a%20table%20of%20contents, if you have some compelling reason to use a parent field instead of a tag that is possible, but it would be less flexible.

Matthew Petty

unread,
May 5, 2015, 12:51:43 AM5/5/15
to tiddl...@googlegroups.com
I knew it was this easy, I just couldn't find it! Silly me. Thank you very much, the tag method works fine.

On Mon, May 4, 2015 at 9:43 PM, Jed Carty <inmy...@gmail.com> wrote:
In the tiddler you linked to the list field sets the order the entries appear in, it doesn't set which entries appear. So tagging something TableOfContents will put it in the table of contents at the first level, and trading something HelloThere will put it in the table of contents as a child of HelloThere.

I have a bit about them here http://inmysocks.tiddlyspot.com/#Creating%20a%20table%20of%20contents, if you have some compelling reason to use a parent field instead of a tag that is possible, but it would be less flexible.

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/PSHNF-_6qto/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/85543489-7910-4e60-9245-17f973473abc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages