Do not put , after the last item in a list

Here is a code I have:

<$list filter="[tag[Contact]]">
<$link />, 
</$list>

This produces a nice , separated list of all ‘Contact’ tiddlers except that even after the last contact, it puts a ,

How can I avoid that?

PS. By the way, this code appears as a cell of a table and therefore, in real life, does not contain any newlines.

Try this, only change “HelloThere” to “Contact” in both places:

<$vars last={{{ [tag[HelloThere]last[]] }}} >
<$list filter="[tag[HelloThere]]">
<$link/><$reveal type="nomatch" tag="span" default=<<last>> text=<<currentTiddler>>>,  
</$reveal>
</$list>
</$vars>

This has been formatted so there should be no newlines.

Here’s a slightly different version that avoids the <span>...</span> generated when using <$reveal>:

<$vars last={{{ [tag[Contact]last[]] }}}>
<$list filter="[tag[Contact]]">
<$link /><$text text={{{ [<currentTiddler>!match<last>then[,]] }}}/>
</$list>
</$vars>

-e

1 Like

This is the third version!

<$list filter="[tag[HelloThere]butlast[]]"><$link/>, </$list>
<$link to={{{[tag[HelloThere]last[]]}}}/>

Hopefully, you will get five and fifth versions if you are patient!
Tiddlywiki and its community are very generous!

When you do not need a link to every tiddler, like processing fields value, use

<$list filter="[tag[HelloThere]join[, ]]">
<$text text=<<currentTiddler>>/>
</$list>

The problem with this version is that it will put a newline after the last item. That’s why my version is so complicated. If the list widget had a tag attribute like the reveal widget does, then the list could be done with span and there would be no final line break.

Hi @Mark_S, your solutions always are interesting!

Just for the giggles (assuming the unicode character shows on your device’s browser):

<$list filter="[tag[Contact]]">
🔸<$link />&nbsp;
</$list>

@EricShulman Thanks. This works just as expected.

Will it be possible to use ’ and’ between last and second-last items?

So, ‘Con1, Con2 and Con3’.

I tried this:

<$vars last={{{ [tag[Contact]last[]] }}} seclast={{{ [tag[Contact]last[2]] }}}>
<$list filter="[tag[Contact]]">
<$link /><$text text={{{ [<currentTiddler>!match<last>then[,]] }}}/><$text text={{{ [<currentTiddler>match<seclast>then[and ]] }}}/>
</$list>
</$vars>

But that did not work. It produced ‘Con1, Con2, and Con3’.

How do I get the correct formatting?

Did you not see my list-sentence macro here Replace "and" in a List of Authors with Comma Except the Last One - #22 by TW_Tones ?