Choosing what field to show with list-links?

So one of the first little changes I make to new TW is modifying the list-links macro so that I can choose to list either by caption (default) or to show the full title.

I was curious if there was a perticular reason as to why this isn’t something you can do by default?

Could doing so cause issues later on with the wiki?

Here is how I do it, in case anyone else would like to use it as well ^^

simply copy/paste below over the original found @ $:/core/macros/list

\define list-links(filter,type:"ul",subtype:"li",class:"",field:"caption",emptyMessage)
\whitespace trim
<$type$ class="$class$">
<$list filter="$filter$" emptyMessage=<<__emptyMessage__>>>
<$subtype$>
<$link to={{!!title}}>
<$let tv-wikilinks="no">
<$transclude field="""$field$""">
<$view field="title"/>
</$transclude>
</$let>
</$link>
</$subtype$>
</$list>
</$type$>
\end
1 Like

Good idea. I think list-links is was one of the first macros, before even captions were thought of or at least widely used, so I don’t think anyone thought of your idea.

Note, I’d recommend that instead of writing "$filter$" you use either '$filter$' or """$filter$""" so titles containing " don’t break it.

I hadn’t thought of that, thanks!

I’m a bit scared to imagine what TW was like without macros, I rely on them so much :sweat_smile:

Hi @Justin_H this is a good idea.

But we can do a lot better with the implementation of this macro now. We can now in a position to avoid the textual substitution entirely. In particular, the new <$genesis> widget makes it possible to replace the clumsy and error prone <$type$ class="$class$"> construction.

\define list-links(filter,type:"ul",subtype:"li",class:"",emptyMessage,field:"title")
\whitespace trim
<$genesis $type=<<__type__>> class=<<__class__>>>
<$list filter="$filter$" emptyMessage=<<__emptyMessage__>>>
<$genesis $type=<<__subtype__>>>
<$link to={{!!title}}>
<$let tv-wikilinks="no">
<$transclude field=<<__field__>>>
<$view field="title"/>
</$transclude>
</$let>
</$link>
</$genesis>
</$list>
</$genesis>
\end
3 Likes

I committed the updated macro for v5.2.4 here:

3 Likes

Thank you Jeremy.

This is an excellent example of how to update a macro to avoid textual substitution for better performance, as well as the utility of the $genesis widget.

1 Like

that’s so cool haha

honestly I’m still trying to wrap my head around the new genesis widget, it’s going to be a real game changer

I had a poke around to find the commit that first adds support for macros, which turns out to be on 8th December 2011, which was just three or four weeks after I left BT and started work properly on TiddlyWiki 5.

Highly recommended: all I did was execute git log > tmp.txt, and then open tmp.txt in my editor and search for some interesting words.

2 Likes

So that’s how you make git log actually usable :star_struck: