ListWidget Fields in Current Tiddler with certain Value

138 views
Skip to first unread message

David

unread,
Apr 20, 2020, 12:53:23 PM4/20/20
to TiddlyWiki
I have this code that illustrates what I'd like to do.  I know I could make each data element a separate tiddler and work with them that way, but for this, I'd like to keep it all in one tiddler.

I'd like to only show fields with a certain value.

I already have a loop that iterates over the fields with a certain prefix, which gets the field names I want to check.  But I don't know how to dynamically access the content/value of the field.

Basically what I want to do is show a list of the values (text in the "checked" attribute) of checked fields.

P.S. "mi" is for menu item, so that I can differentiate these fields from default or other tiddler fields.

|!Item|!Customize|!Notes|
|<$checkbox field="mi_chalupa" checked="Chalupa" unchecked="No" default="No"> Chalupa</$checkbox> |Chipotle Sauce||
|<$checkbox field="mi_tripleupa" checked="Tripelupa" unchecked="No" default="No"> Tripelupa</
$checkbox> |||
|<$checkbox field="mi_nacho_fries" checked="Nacho Fries" unchecked="No" default="No"> Nacho Fries</$checkbox> |||

!! Chosen Items

<!-- This is dynamic, but
   1. I can't get the field's content/
value to display
   
2. I only want to display the content/value of the field if it is not "No", or some other string, I don't care what.
-->
<$list filter="[all[current]fields[]prefix[mi_]]" variable="x">
<$view field="<x>" /><br />
</$list>

---

<!-- This does what I want, but is not dynamic, and shows Tiddler name instead of field value -->
<$list filter="[all[current]!mi_chalupa[No]]" variable="x">
<<x>><br />
</$list>




Mat

unread,
Apr 20, 2020, 5:53:03 PM4/20/20
to TiddlyWiki
<$list filter="[all[current]!mi_chalupa[No]]">
{{!!mi_chalupa}}<br />
</$list>

The short form for accessing any field is {{!!fieldname}} or, if in another tiddler or context, {{tiddlername!!fieldname}}

<:-)

David

unread,
Apr 20, 2020, 11:25:51 PM4/20/20
to TiddlyWiki
Thank you so much, but as I mentioned in the comment for that section, that is not dynamic.  I have the field name in a variable "x" and this is what I thought, and I tried other forms of accessing the var, but it doesn't work...

<!-- This is dynamic, but shows all fields, even ones marked "No".  I want only "Yes" -->

<$list filter="[all[current]fields[]prefix[mi_]]" variable="x">
{{!!<x>}}<br />
</$list>



Mark S.

unread,
Apr 21, 2020, 12:08:29 AM4/21/20
to TiddlyWiki
I don't quite understand your question. If you only want fields that match value "Yes", then
what is the point of retrieving the value -- it will always be "yes"?? Here's code that does
what you literally asked for:

<$list filter="[all[current]fields[]prefix[mi_]]" variable="field">
<$list filter="[all[current]get
<field>match[Yes]]" variable=dummy>
<
<field>>: Yes
</$list></$list>

It finds the fields starting with mi_ and reports them only if they contain "Yes". As you may note,
I just hardcoded "Yes", since the inner list guarantees that "Yes" is all the field will have.

Mark S.

unread,
Apr 21, 2020, 12:25:22 AM4/21/20
to TiddlyWiki

Ok, I think this is what your want:

<$list filter="[all[current]fields[]prefix[mi_]]" variable="field">
<$list filter="[all[current]get<field>!match[No]]" variable=value>
<
<field>>: <<value>><br/>
</$list></$list>

So it reports fields and value where the field name matches mi_ and the contents don't match "No".

David

unread,
Apr 21, 2020, 8:57:22 AM4/21/20
to TiddlyWiki
Yes.  Exactly right.  Perfect.  Thank you, Mark!

How to reference a variable name as the field selector was the key.
Reply all
Reply to author
Forward
0 new messages