I am not really sure how to describe my question, here is what I try:
I have a different tiddlers, some with field caption containing text, some with field caption containing transcluded value from another tiddler (eg: {{$:/language/caption}}), some without field caption.
I’d like to list them using $list widget and link to them showing caption value if exists or title if not.
I tried this :
<$list filter="[tag[ConditionnalFilter]]">
<$link to=<<currentTiddler>>>
<$text text={{{ [all[current]get[caption]else{!!title}] }}}/>
</$link><br>
</$list>
but when the caption field contains a transcluded value, the link being rendered is literal field value {{$:/language/caption}} and not the content of this transclusion.
I’ve found a workaround using two filters :
<$list filter="[tag[ConditionnalFilter]]">
<$link to=<<currentTiddler>>>
<$list filter="[all[current]has[caption]]">{{!!caption}}</$list>
<$list filter="[all[current]!has[caption]]"/>
</$link><br>
</$list>
I’d like to be sure that there isn’t a prettiest way to do this, or something I’ve missed.
Here is a wiki for demo
Instead of
<$list filter="[all[current]has[caption]]">{{!!caption}}</$list>
<$list filter="[all[current]!has[caption]]"/>
you can use
<$transclude field={{{ [<currentTiddler>has[caption]then[caption]else[title]] }}}/>
enjoy,
-e
vilc
January 26, 2024, 2:59pm
3
Just a slightly more elegant way possible with the new conditional syntax in v5.3.3 would be:
<$list filter="[tag[ConditionnalFilter]]">
<$link to=<<currentTiddler>>>
<% if [all[current]has[caption]] %>
{{!!caption}}
<% else %>
{{!!title}}
<% endif %>
</$link><br>
</$list>
Edit: of course Eric’s solution above is much better and more concise.
Good point @vilc . Of note for @hrOArdan is both your solutions transclude the caption field resulting in it being interpreted as wiki text.
@hrOArdan you may be supprised but your can transclude something that transcludes something that tra…
I knew I would get useful knowledge from this, thank all of you !
@vilc this approach in nice because as it transcludes the caption field and as a result wikifies it but all using a short syntax.
However, here I make it more compact, simplify its name, generalise it and add a feature.
\procedure caption(indicator:"Ⓒ") <% if [all[current]has[caption]] %>{{!!caption}}^^<<indicator>>^^<% else %>{{!!title}}<% endif %>
In a tiddler tagged $:/tags/Global
Using it;
<$list filter="[tag[ConditionnalFilter]]">
<$link><<caption>></$link><br>
</$list>
compact - single line procedure
lets call it caption, we all know if its not available it uses title
make it a global macro, define once use multiple times with simply <<caption>>
But default it indicates its a caption “ExamplesⒸ ” however this can be changed or hidden with <<caption " ">>