Extracting and grouping by multivalue field

69 views
Skip to first unread message

Darek Bobak

unread,
Sep 14, 2020, 6:51:34 AM9/14/20
to TiddlyWiki
My tiddlers have a field "sites", in which I store multivalue site names, in format:
Rörshein Zeitlarn [[Vedrovice V]] [[Dzierżysław I]]

The code below creates a hierarchical list showing tiddlers names and list of sites assigned to each tiddler (look at the attachment).

<$list filter="[has[sites]]">
  <ul><li>
    <$link><<currentTiddler>></$link>
    <$list filter="[enlist{!!sites}sort[title]]" variable="mySites" >
       <ul><li> <<mySites>> </li></ul>
    </$list>
  </li></ul>
</$list>

But I can not get the reverse order,ie to group the tiddlers by the sites, like that:
* Albersdorf
    * tiddler 1
    * tiddler 2
* Ksar Akil
     * tiddler 1
     * tiddler 3

Would someone help?

best
Darek
Zrzut ekranu 2020-09-14 124902.png

Felicia Crow

unread,
Sep 14, 2020, 2:14:17 PM9/14/20
to TiddlyWiki
Hi,

if you have a way to filter for all site tiddlers you could then use the contains operator to see if the site is contained in the sites field. Something like this:
<ul>
<$list filter="[!has[draft.of]tag[Site]sort[title]]" variable="site">
<li>
<$link to=<
<site>> />
<ul>
<$list filter="[!has[draft.of]has[sites]contains:sites
<site>sort[title]]">
<li><<currentTiddler>></li>
</$list>
</ul>
</li>
</$list>
</ul>

Which would look something like this - although in your case with more and meaningful data:

Regards,
Felicia

Darek Bobak

unread,
Sep 14, 2020, 2:40:42 PM9/14/20
to TiddlyWiki
Felicia, you are great! After small modification it works like charm:

<ul>
    <$list filter="[each:list-item[sites]sort[title]]" variable="site">

        <li>
            <$link to=<<site>> />
            <ul>
                <$list filter="[!has[draft.of]has[sites]contains:sites<site>sort[title]]">
                    <li>
                        <$link to=<<currentTiddler>> />

                    </li>
                </$list>
            </ul>
        </li>
    </$list>
</ul>


Thank you!
Darek
Zrzut ekranu 2020-09-14 203902.png
Reply all
Reply to author
Forward
0 new messages