How to sort tiddlers by title inside tag macro?

118 views
Skip to first unread message

talha131

unread,
Feb 7, 2019, 4:40:50 PM2/7/19
to TiddlyWiki
Tag macro which is shown at two places.

1. Tag manager
2. Under the tiddler title

It shows a list of tiddlers. How do I sort them by title? It can be done manually using drag and drop. But can it be done automatically?

TonyM

unread,
Feb 7, 2019, 7:29:11 PM2/7/19
to TiddlyWiki
Talha,

I am not sure what you mean by "Tag Macro" but the Tag manager is a system tiddler $:/TagManager and in this tiddler the order is determined for the tag manager list, but it seems to be by title already?

When viewing a tiddler the tags are displayed using the $:/tags/ViewTemplate tag on $:/core/ui/ViewTemplate/tags and this uses filter="[all[current]tags[]sort[title]]" which will sort a tiddlers tags by title.

I am not sure where your issue is. Please provide more info!

Tony

Mark S.

unread,
Feb 7, 2019, 11:35:10 PM2/7/19
to TiddlyWiki
When you click on a tag and see a list, and then drag an item in the list, where is that sort-order stored? It's stored in the "list" field of the tiddler with the same name as the master tag that you clicked on. So, for instance, if you go to TiddlyWiki.com and open the HelloThere tiddler, and look at the "list" field, you will see the tiddlers that reference "HelloThere" listed in the field. They are not in alphabetical order.

If you copy the following into a tiddler at TiddlyWiki.com, and press the "Sort" button, the corresponding tiddlers will be sorted:

\define alphasort() <$action-listops $tidd ler="HelloThere" $subfilter="+[sort[]]"/>

<$button actions=<<alphasort>>
Sort "HelloThere"
</$button>

You can make changes to this code to sort the list field of any tiddler.

The catch is, that there is no requirement that all tiddlers that are tagged by a tiddler are listed in its list field. This version will populate the field AND sort it:

\define alphasort() <$action-listops $tiddler="HelloThere" $filter="[tag[HelloThere]sort[]]"/>

<$button actions=<<alphasort>>>
Sort "HelloThere"
</$button>


It's left as an exercise to the student to turn the code into a generic macro that can be used on any tiddler ;-)

-- Mark

TonyM

unread,
Feb 7, 2019, 11:38:53 PM2/7/19
to TiddlyWiki
Fantastic Share Mark

Mohammad

unread,
Feb 8, 2019, 3:01:29 AM2/8/19
to TiddlyWiki
Thanks Mark.
 I do the exercise.

Added to TW-Scripts.

Mohammad

unread,
Feb 8, 2019, 4:03:19 AM2/8/19
to tiddl...@googlegroups.com
This may be the solution of the exercise given by Mark:

\define tagsort(mainTag, label:"Sort Tags", order:"ascend")
<$button>$label$
<$reveal type="match" default="ascend" text=<<__order__>> >
<$action-listops  $tiddler=<<__mainTag__>>  $filter="[tag<__mainTag__>sortan[]]"/>
</$reveal>
<$reveal type="nomatch" default="ascend" text=<<__order__>> >
<$action-listops  $tiddler=<<__mainTag__>>  $filter="[tag<__mainTag__>!sortan[]]"/
>
</$reveal>
</
$button>
\end


  • It gets a main tag to sort based on that.
  • It can sort in ascending or descending order
  • It has the button inside and gets a label to be more semantic
  • It sort alpha-numerically

--Mohammad

On Friday, February 8, 2019 at 8:05:10 AM UTC+3:30, Mark S. wrote:

talha131

unread,
Feb 10, 2019, 1:58:55 PM2/10/19
to TiddlyWiki

Thank you all for help. Mohammad’s solution to Mark’s exercise is perfect. It solved my issue.

talha131

unread,
Feb 10, 2019, 3:14:15 PM2/10/19
to TiddlyWiki

Using Mohammad macro, I cannibalized the replace-tag wizard macro to create following wizard

\define sortTagWizard()

<$edit-text
tiddler="$:/temp/sort-tag-tiddlers"
field="sortTag"
tag="input"
default=""
placeholder="select tag to sort"
focusPopup=<<qualify "$:/state/popup/sort-tag-tiddlers">>
class="tc-popup-handle"/>
<$button
popup=<<qualify "$:/state/popup/sort-tag-tiddlers">>
class="tc-btn-invisible tc-btn-dropdown"
tooltip={{$:/language/EditTemplate/Tags/Dropdown/Hint}}
aria-label={{$:/language/EditTemplate/Tags/Dropdown/Caption}}>
{{$:/core/images/down-arrow}}</$button>
&nbsp;
<$reveal state="$:/temp/sort-tag-tiddlers!!sortTag" type="nomatch" text="">
<$button class="tc-btn-invisible tc-btn-dropdown">
<$action-deletetiddler $tiddler="$:/temp/sort-tag-tiddlers"/>
{{$:/core/images/close-button}}
</$button>
</$reveal>
<$reveal state="$:/temp/sort-tag-tiddlers!!sortTag" type="nomatch" text="">
<$macrocall $name="tagsort" mainTag={{$:/temp/sort-tag-tiddlers!!sortTag}} label="Sort {{$:/temp/sort-tag-tiddlers!!sortTag}} tag"/>
</$reveal>
<div class="tc-block-dropdown-wrapper">
<$reveal
state=<<qualify "$:/state/popup/sort-tag-tiddlers">>
type="nomatch"
text=""
default="">
<div class="tc-block-dropdown">
<$linkcatcher to="$:/temp/sort-tag-tiddlers!!sortTag">
<$list filter="[tags[]search:title{$:/temp/sort-tag-tiddlers!!sortTag}sort[]]">
{{||$:/core/ui/Components/tag-link}}
</$list>
</$linkcatcher>
</div>
</$reveal>
</div>
\end

<<sortTagWizard>>

It does not take advantage of sort order option, due to lack of my skills. What you get is

Hope someone would find it useful.

Mohammad

unread,
Feb 10, 2019, 3:34:00 PM2/10/19
to TiddlyWiki
Hi Talha,
Many thanks for sharing. I want to add it to TW-Scripts.
Experimenting with it on tiddlywiki.com does not show for me the sort button!
Could you have a look and tell me what is wrong?

--Mohammad

Mohammad

unread,
Feb 10, 2019, 3:37:34 PM2/10/19
to TiddlyWiki
Oh, Sorry!
I got the point, you have not included the tagsort in the below code!


--Mohammad

On Sunday, February 10, 2019 at 11:44:15 PM UTC+3:30, talha131 wrote:

Mohammad

unread,
Feb 10, 2019, 3:38:26 PM2/10/19
to TiddlyWiki
Added to TW-Scripts.


On Sunday, February 10, 2019 at 11:44:15 PM UTC+3:30, talha131 wrote:

TonyM

unread,
Feb 10, 2019, 8:36:33 PM2/10/19
to TiddlyWiki
Mark,

Perhaps this could be made into a plugin that is displayed inside the tag drop down similar to the Open All Button http://openall.tiddlyspot.com/

Regards
Tony


On Friday, February 8, 2019 at 3:35:10 PM UTC+11, Mark S. wrote:

talha131

unread,
Feb 11, 2019, 12:15:18 AM2/11/19
to TiddlyWiki
Thanks a lot.

talha131

unread,
Feb 11, 2019, 1:26:29 AM2/11/19
to TiddlyWiki

Tony this is not a plugin but gets the job done.

I tag this tiddler with $:/tags/TagDropdown.

\define tagSortFunc(mainTag, order:"ascend")

<$reveal type="match" default="ascend" text=<<__order__>> >
<$action-listops  $tiddler=<<__mainTag__>>  $filter="[tag<__mainTag__>sortan[]]"/>
</$reveal>

<$reveal type="nomatch" default="ascend" text=<<__order__>> >
<$action-listops  $tiddler=<<__mainTag__>>  $filter="[tag<__mainTag__>!sortan[]]"/>
</$reveal>


\end

\define sortInTagDropdown()

<$button tooltip="Sort tiddlers A → Z" aria-label="Sort tiddlers A → Z" class='tc-btn-invisible'>Sort {{!!title}} tiddlers A → Z
<$macrocall $name="tagSortFunc" mainTag={{!!title}}/>
</$button>

<$button tooltip="Sort tiddlers Z → A" aria-label="Sort tiddlers Z → A" class='tc-btn-invisible'>Sort {{!!title}} tiddlers Z → A
<$macrocall $name="tagSortFunc" mainTag={{!!title}} order="no-ascend"/>
</$button>

\end

<<sortInTagDropdown>>

The result is

The eject icon is from openall plugin.

This tiddler needs CSS tweaking though.

Mohammad

unread,
Feb 11, 2019, 1:49:42 AM2/11/19
to TiddlyWiki
Wonderful job!
Why not to have this in the core! It can have an option in the Setting to be displayed or hidden.

Added to TW-Scripts.

Cheers
Mohammad
Reply all
Reply to author
Forward
0 new messages