Nested list widgets and variables

Hello. I am wondering if I could get help understanding the functioning of the list widget.

Here was my aim tonight:

“I want the set of all tiddlers who do not have a field where standalone equals true who are tagging other tiddlers. Then I want to list the tiddlers they tag on their tiddler.”

I think I have achieved this:

<$list filter="[all[current]!contains:standalone[true]tagging[]count[]!match[0]]" variable='moo'>
<div class='grid1_1_1'>
<$list filter="[all[current]tagging[]]">
<div>
<$link to={{!!title}}><$image source={{!!my_thumb}} /></$link>
<$link to={{!!title}}><b><$view field="title"/></b></$link>
</div>
</$list>
</div>
</$list>

I am wondering why adding the unused variable attribute on the first list tag makes this function as expected (i.e., recursively).

Welcome JenniferS

In side the list with variable='moo' will change the variable “moo” for each item generated in the list. However in your example moo is given only one value. The default is variable currentTiddler.

In the inner list because you have “nested them” each value of “moo” will be available, but this only happens once, and you never reference moo <moo> in filters or <<moo>> in wikitext.
As no variable= is set you use the default variable currentTiddler inside the inner list.

This is important here because when you reference fields using the short form {{!!fieldname}} eg title the tiddler it is applied to is the <<currentTiddler>>

By the way, the long form of the title transclude is;
<$transclude field="title"/> and you could add mode=block or mode=inline

  • In this form where the default tiddler is used, there no need to write is tiddler=<<currentTiddler>> but tiddler says this is where to get the template from.

I hope this illuminates it a little more.

Thank you! I appreciate your reply. I have read it several times, and I think I am still unclear as to why the nesting goes unrealized unless I declare a variable on the parent widget call. I think I hear you saying that what is important is that the current tiddler is given the proper (nested) context.

If it helps

The outer wiki of yours has only one result, thus operates only once and sets the moo variable. You could have used the Set widget filter= parameter as well.

<$set name=moo filter="[all[current]!contains:standalone[true]tagging[]count[]!match[0]]" >

inner list

</$set>

The inner list will most likely generate multiple cases. Because no variable name is set, the currentTiddler variable will be used.

  • This inside the inner list this will be used for each resulting “currentTiddler”
<div>
<$link to={{!!title}}><$image source={{!!my_thumb}} /></$link>
<$link to={{!!title}}><b><$view field="title"/></b></$link>
</div>

which is fortunate because you are using {{!!title}} and {{!!my_thumb}}to access field contents. This form of transclusion defaults to the “currentTiddler”. Had you use the variable moo2 on the list it would not work.

It will become a lot clearer in time, and you can always ask here again,
No question is a bad question!

1 Like

When the tiddler text is rendered, the core UI sets “currentTiddler” to the title of the current tiddler. This allows us to use eg: {{!!field-name}} without the need to specify the title again.

The list widget automatically uses the name: currentTiddler as the default name for the “variable” parameter. …

So if you don’t set it to “moo” your [all[current]tagging[]] in the inner list wouldn’t work anymore. You expect that filter to be the “title” of the tiddler, where the code is. … right?

all[current] uses the value of the “currentTiddler” variable.

So if the variable name wouldn’t be set to “moo” in the outer list. It would default to “currentTiddler”, which would break the inner filter.

Sorry it’s a bit confusing, but that’s basically it.

1 Like

Thank you both. I would like to understand this!

What I’m hearing is that the result of the filter run on the first call to the list widget is preserved once I declare a variable on it. Now that set has somewhere to “go.” And the subsequent, nested list call uses that set as its reference point. It doesn’t matter what I name the variable, and it is not empty.

I feel like I am close, but not quite there. Perhaps I am thinking too concretely about “sets.”

I.e., is
<$list filter="[all[current]tagging[]]">
equivalent to
<$list filter="[moo[current]tagging[]]">
?

The key observation about your outer list and my set is the filter contains the count operator. This reduces the output of the filter to one value or no value (!maych[0])

Perhaps I was wrong to make it a set if you only want the inner list to be rendered if moo not equal to zero.

It depends on the filter in a list and any inputs if its content will be rendered never, once or multiple times.

No your two list are different. The second is invalid.

The first will list all tiddlers tagged by the current tiddler wich may be none, once or more. It will set the title of each tiddler to currentTiddler or the named variable one or more times.

I hope I am helping.

No. Your outer list-widget is just an “if”, where the variable isn’t used at all. You only need to assign a variable name: moo, because otherwise your inner list wouldn’t work.

For constructions like this we sometimes use variable=ignore so the next user who reads it, knows, that the list-widget is used as an “if” and the variable it creates isn’t needed later in the code

2 Likes

Yes and against the best advice I no longer use variable=nul and use variable=~>

<$list filter="if only" variable=~>
   if here where currentTiddler is still the original tiddler.
</$list>

Other little tricks are;

  • is if you have “lost the current tiddler” <<storyTiddler>> does indicate the “current” tiddler in the story.
  • using the <<transclusion>> variable can give you more info.

Post script:

  • Recently I have named the variable something useful if the value returned is of use. More of a self documenting feature.
<$list filter="determine if is design mode then[design]]" variable=mode>
   if here where currentTiddler is still the original tiddler. And if I needed it `<<mode>>` is available although it will always be the same value here.
</$list>