Joining list results without repeating the category title

Sorry that I have asked this before and have to bother you again. Unfortunately I didn’t document it and can’t find it. I dug around a bit, but alas.

I basically want this:

<$list filter="[all[current]tagging[]sort[specifics]] -[[Tags]]"><b><$view field="specifics"/></b><span class="indent1"><$transclude field="text" mode="block" /><span class="thingray"><$view field="source"/>, <$view field="pagenumber"/>. <$link>*</$link></span></span><br></$list>

but for output where two or more etries have the same text in the specifics field, they are joined together under one “view field specifics” heading, rather than having the “view field specifics” heading displayed before every single entry.

So the output would be

A
Apple
Atari

Rather than

A
Apple
A
Atart

It looks to me as if you want a list of unique specifics field values, each with a nested list of tiddlers that have those values. Is that right? If so, here’s some code you can test:

<$list filter="[tag<currentTiddler>each[specifics]get[specifics]sort[title]]" variable="specifics">
<!-- ^ This gives us a list of unique values of the specifics field, which we assign to the <<specifics>> variable.
In this case, sort[title] means "sort the results of the previous filter step alphabetically" so we're sorting !!specifics values, as you did in your original code. -->
	<b><<specifics>></b>
	<span class="indent1">
		<$list filter="[tag<currentTiddler>specifics<specifics>] -Tags">
		<!-- ^ This gives us a list of tiddlers whose "specifics" field matches the value above. -->
			<$transclude mode="block" /> <!-- field=text is the default, so we can leave it out -->
			<span class="thingray">
				{{!!source}}, {{!!pagenumber}}. <$link>*</$link>
			</span>
		</$list>
	</span>
</$list>

The each operator has always been a little unintuitive to me. If you’re interested, I wrote more about its various permutations here, but the short version is that it returns the first tiddler it finds that has a value of your chosen field (here, !!specifics) that’s not already represented by another tiddler in the list. The important thing is that each[specifics] returns a list of tiddler titles; to get a list of the values of the specifics field, we need to pair it with get[specifics].

3 Likes

Thank you Emily, for both the code and the explanations! Going to document this right now!