Access the Parent Tiddler's Field when Inside a ListWidget Loop

88 views
Skip to first unread message

David

unread,
Jul 10, 2020, 10:00:52 AM7/10/20
to tiddl...@googlegroups.com
I am looping over some tiddlers with the ListWidget.

I was using the variable attribute, but have removed that to access fields directly (via {{!!fieldname}} type calls, and for best practice reasons, etc.

But I need to know  how to refer to the parent tiddler's field (not the child's) in a reveal's state attribute.

This (the "!!edit_priorities" state, which refers to a field in the parent tiddler) used to work when the filter was using the item variable, but needs some tweaking now, because the "scope" it's in has changed to the child tiddler (I assume).

<$list filter="[tag[Task]!tag[Done]]" >
<$reveal type="match" state="!!edit_priorities" text="1">
<$edit-text field="priority" size="3" />
</$reveal>
<nobr> <$checkbox tag="Done"/> <$link>{{!!title}}</$link></nobr>
<br/>
</$list>

So, in words, what I'm trying to do is list todo tasks that are not tagged as done.  In that tiddler as well is a field, which I use to control the display of the Priority edit boxes.  If I set that field to '1', then I want the reveals to show the edit boxes for each task.

Thank you!

TW Tones

unread,
Jul 10, 2020, 10:33:23 AM7/10/20
to TiddlyWiki
David,

The list widget by default changes the currentTiddler value for each title it generates.
In you code you are trying to look at the fields in each of the tiddlers the filter finds.

<$list filter="[tag[Task]!tag[Done]]" variable=currentTiddler>

<$reveal type="match" state="!!edit_priorities" text="1">
<$edit-text field="priority" size="3" />
</$reveal>
<nobr> <$checkbox tag="Done"/> <$link>{{!!title}}</$link></nobr>
<br/>
</$list>
In bold is what the default is without giving it.

Now if you do not need to use the lists titles inside the list widget use another variable
variable=nul is what I use if the code does not use the title, however if it did it could use 
<<nul>>

A Quick look at your code suggests it is all you need to make it wok
<$list filter="[tag[Task]!tag[Done]]" variable=nul>

<$reveal type="match" state="!!edit_priorities" text="1">
<$edit-text field="priority" size="3" />
</$reveal>
<nobr> <$checkbox tag="Done"/> <$link>{{!!title}}</$link></nobr>
<br/>
</$list>

Basically it is a simple convention If I don't use the variable in the list statement I call it nul, or If I do use the list result I chose a meaningful name lets say list-item
Most widgets then let you specify 
tiddler=<<list-item>>
or in another parameter

By using the variable= the shorthand ways such as 
{{!!fieldname}}
Continue to work.

Did you know if you allow the currentTiddler to change while listing a number of tiddlers there are other short cuts
{{||$:/core/ui/Buttons/edit}} will give you an edit button for the current tiddler.

Regards
TW Tones

Eric Shulman

unread,
Jul 10, 2020, 10:44:26 AM7/10/20
to tiddl...@googlegroups.com
To do what you want, you'll *need* to use variable="..." in the $list widget.
This will allow you to keep the "parent" tiddler context as the currentTiddler.

Of course, you have references *inside* the $list loop that you would like
to keep simple by having the $list use currentTiddler, but that would defeat
what you want to do with the "edit_priorities" flag field.

One way to achieve a mix of both, is to explicitly use the tiddler="..." widget
parameter or wrap content in a $tiddler widget to set the inner context.

Something like this:
<$list filter="[tag[Task]!tag[Done]]" variable="item">

   <$reveal type="match" state="!!edit_priorities" text="1">
      <$edit-text tiddler=<<item>> field="priority" size="3" />
   </$reveal>
   <$tiddler tiddler=<
<item>>>
     
<nobr> <$checkbox tag="Done" /> <$link /></nobr><br/>
   </$tiddler>
</$list>

notes:
* the $edit-text uses an explicit tiddler=<<item>> param to point at the individual task tiddler
* the $checkbox and $link are surrounded by a $tiddler widget that sets the <<currentTiddler>> to the <<item>> value
* I've used the "short form" of <$link />, since you are just linking to the <<currentTiddler>>

enjoy,
-e

David

unread,
Jul 10, 2020, 5:56:25 PM7/10/20
to TiddlyWiki
Thanks guys!!
Reply all
Reply to author
Forward
0 new messages