PaulH
April 29, 2022, 7:01pm
1
Can I display a transclusion a number of times equal to a value in a field?
I have an image I use to represent a value and I want to show it in tiddlers a number of times equal to a field value.
I’ve done searches but I have this nagging feeling I’m not phrasing things properly.
<$list filter="[range[0],{!!myfield}]">
{{my-image}}
</$list>
Or alternatively:
{{{ [range[0],{!!myfield}] ||my-image }}}
https://tiddlywiki.com/#range%20Operator
PaulH
April 29, 2022, 10:39pm
3
Almost there, but I must not be understanding something. I used your exact code and substituted in my field name and tiddler name.
It always displays 1 image and then adds a number of my image equal to the value.
In other words, if my value is 3 it displays 4 of my image.
Thank you for your help.
Thanks @saqimtiaz for your solution!
range is a generator operator, meaning that whatever its input is, it will generate an output.
So I faced a problem when the field is empty, isn’t numeric or is 0.
Here’s the code I came up with:
<$edit-text field=stars size=3/><br/>
<$list filter="[<currentTiddler>has[stars]get[stars]compare:integer:gt[0]]" variable=myStars>
{{{ [range[1],<myStars>] || $:/core/images/star-filled }}}
</$list>
You can play with the value of the stars field to see the result.
Fred