Sorting table of contents by multiple parameters

205 views
Skip to first unread message

Fadel M

unread,
Apr 22, 2018, 12:32:03 PM4/22/18
to TiddlyWiki
Hi,

From what I understand, the default sort for the table of contents is by the created field. The list field overrides the sort by putting the listed tiddler titles on top in listed order.

What I'd like to achieve is to sort the contents by title, but keep the ability of the list field to prioritize some of the tiddlers. I'm not sure how to do this, since I'm not very familiar with the inner workings. 

The way I imagine it is by populating the list field as below
list: Tiddler1 Tiddler2 Tiddler3 sort[title] Tiddler200 Tiddler300

But of course, this doesn't work. Could anyone point me in the right direction?

Mark S.

unread,
Apr 22, 2018, 3:29:12 PM4/22/18
to TiddlyWiki
If you want to use the existing toc macros then you will need to modify the list field of your root (top) tiddler.  Here's an example that rearranges the default listing for HelloThere on tiddlywiki.com, :-) putting Examples first, and Discover TiddlyWiki last.

<$button> <$action-listops $tiddler=HelloThere $field="list" $filter="Examples [tag[HelloThere]![Examples]![Discover TiddlyWiki]sort[]] [[Discover TiddlyWiki]]"/> Populate 'myfield' </$button>


For your situation,  you will need some way to discriminate sorted tiddlers from non- sorted tiddlers. Then you can use a filter in your button like

Tiddler1 Tiddler2 Tiddler3 [tag[sorted]sort[title]] Tiddler200

--Mark

Fadel M

unread,
Apr 22, 2018, 4:04:04 PM4/22/18
to TiddlyWiki
Thanks for replying! That's a good way to do it.

Ah, so there's no way to do it without excluding the unsorted tiddlers from the sort?
I can't understand how the default sort does it though. You just have to write the name of the tiddlers you want first in the list field, and the rest are automatically sorted by created. Is it just that it's a more low level thing than toc macros?

Also, while this solution is more than enough for my purposes, I'm curious as to whether there is a way to do it automatically without a button? Perhaps by modifying the way the macro works?

Mark S.

unread,
Apr 22, 2018, 6:31:01 PM4/22/18
to TiddlyWiki
I think you would have to re-write the macro. There is a sort argument for the macro, but it would get applied at every sub-level so wouldn't be useful unless you only have one level of tiddlers.

-- Mark

TonyM

unread,
Apr 22, 2018, 9:27:19 PM4/22/18
to TiddlyWiki
Fadel,

As a little side note/brain dump, since what you are doing here is effectively altering the order of items tagging a given tiddler you can use the show as tag pill.


{{TableOfContents||$:/core/ui/TagTemplate}}
or use the macro
<<tag TableOfContents>>

The Popup list of items tagging TableOfContents is thus sort-able using drag and drop, try it. I always install the Open All plugin $:/plugins/ajh/openall (I am trying to locate the Source) which adds the ability to open all items so tagged from the Tag pill popup.
Note: all tiddlers tagged with the current tiddler can also be found in Info button tagging, however by default this is not drag-able (as yet).

Once you have a populated list in the relevant tiddler eg TableOfContents in the "list" field you could perhaps provide alternate ways to sort the items in this list with a click. Alpha, date field etc.. I am yet to explore this in detail.

If you use the macrocall method to invoke the tag macro you can make this use the current tiddler
<$macrocall $name="tag" tag=<<currentTiddler>>/>
Thus this can be placed in a tiddler tagged $:/tags/ViewTemplate to appear in all tiddlers.

Alternatively I have just placed <$macrocall $name="tag" tag=<<currentTiddler>>/> in the core tiddler 

$:/core/ui/ViewTemplate/subtitle 

NB: This will over ride the shadow tiddler.

Wrapping it in the following, it will only show if the current tiddler tags at least one tiddler.

<$list filter="[is[current]tagging[]limit[1]]" variable=null>
<$macrocall $name="tag" tag=<<currentTiddler>>/>
</$list>

I hope this gives you some thing to play with.

Regards
Tony

Fadel M

unread,
Apr 24, 2018, 3:00:08 PM4/24/18
to TiddlyWiki
"I think you have to re-write the macro."

I just took a look at the macro tiddler... yeah... that's not happening any time soon :D
Oh well, I guess I'll have to make do with what's available right now.

Fadel M

unread,
Apr 24, 2018, 3:46:46 PM4/24/18
to TiddlyWiki
Hi Tony,

I had no idea I could re-arrange by drag and drop from the tag pill drop down, thanks for the pointer!

I couldn't think of a creative use for the code examples you gave though. It seemed to me like the functionality is already built in?

TonyM

unread,
Apr 24, 2018, 6:42:38 PM4/24/18
to TiddlyWiki
Fadel,

The the code examples lets you create a "tag Pill" that appears on any tiddler that is used to tag other tiddlers. Thus you have immediate access to the tag pill such that you can reorder  them.

Glad I could help
Regards
Tony

Mark S.

unread,
Apr 24, 2018, 7:04:07 PM4/24/18
to TiddlyWiki
OK, there is another way, if you don't mind putting sort criteria in your tiddlers. See:

https://tiddlywiki.com/#How%20to%20change%20the%20sort%20order%20of%20sub-branches%20in%20a%20TOC%20macro

for details.

Fadel M

unread,
Apr 25, 2018, 12:51:46 PM4/25/18
to TiddlyWiki
Yeah I tried that one, but I wasn't able to adapt it to my use case. It seems to be easy to adapt for a specific standard sort criteria (title,created,modified...), but isn't clear on how to use it to achieve a manual "list" sort.

Fadel M

unread,
Apr 25, 2018, 12:59:33 PM4/25/18
to TiddlyWiki
I understand, but what I'm asking is isn't that functionality already built into the default tiddlywiki?

In the version that I'm using, which is the same as the version on the main tiddlywiki.com page, if you tag tiddler A with another tiddler B, a tag pill appears under the title, which you can click to display a list of all tiddlers tagging tiddler B, which can be reordered by drag and drop.

Is what you suggested any different? Maybe I'm missing something. 

Regards.

TonyM

unread,
Apr 25, 2018, 10:08:08 PM4/25/18
to TiddlyWiki
Fadel,

Any where you want you can extend access to the tag pill for opening or organising items with particular tags, my examples added this to the view template so it automatically appears on every tiddler.

Other wise add it to you wiki text as follows.

eg The Current Tiddler
{{||$:/core/ui/TagTemplate}}

or a particular tagname
{{tagname||$:/core/ui/TagTemplate}}

If the current tiddler is so tagged or not. That is all

Regards
Tony
Reply all
Reply to author
Forward
0 new messages