How to get an array of values from a field?

I have some tiddlers like S11, S12,… and will put them in other tiddlers’ exmaples field.

I wrote a viewtemplate like:

<$vars examples={{!!examples}}>
<$link to=<<examples>>>
<<examples>>
</$link>
</$vars>

And it will give me the link to the example tiddler:

flameshot

This is what I want. However, what if I would put two or more tiddlers into examples field making it an array of tiddlers?
Like examples: S11, S12
How could I treat the value of examples field as an array? Since it seems not possible to run js directly in viewtemplate, is there any other method for my situation?

Hi, Welcome!

A shortcut for testing is:

{{{ [enlist{!!examples}] }}}

See: enlist operator used with filters

If the example field uses eg: S12 S13 [[title with spaces]] you need to cover titles with space in braces

A more verbose version, where you can see, what’s going in is this

<$list filter="[enlist{!!examples}]" variable="element">
<$link to=<<element>> ><<element>></$link> |
</$list>

There is a lot going on here. {{{ }}} is a shortcut for

<$list filter="[enlist{!!examples}]">
<$link />
</$list>

See the https://tiddlywiki.com/#LinkWidget for the default settings.

If you use {{!!examples}} that’s called a transclusion using a text-reference with the default tiddler is currentTiddler

Text references can also be used within filters, but they only have 1 { bracket there not 2 as in the transclusion

See: https://tiddlywiki.com/#Transclusion
and: https://tiddlywiki.com/#TextReference

have fun!
mario

2 Likes

You can use the enlist filter operator to take a field containing several values, and split it into separate values for further processing with a $list widget.

Using your example:

<$list filter="[enlist{!!examples}]" variable="this_example">
   <$link to=<<this_example>>/>
</$list>

Notes:

  • TiddlyWiki uses SPACE-separated lists, so the contents of the !!examples field would be “S11 S12” (without commas). If an individual tiddler title in the field includes any spaces, you will need to enclose that title inside doubled square brackets, like this: “S11 [[S12 has spaces]]”
  • The $list widget gets the contents of the !!examples field from the current tiddler and uses the enlist filter operator to split it into separate values, each of which is assigned to the variable this_example, for processing one at a time.
  • The $link widget has an abbreviated form: when the text to display has the same value as the to=... widget parameter, you can avoid repeating the value and just end the $link widget with a closing /> as shown in the example above

-e

2 Likes

That’s what I need! Thanks!

It helps! Thank you !