list fields filtered by content

176 views
Skip to first unread message

Dave

unread,
Jul 29, 2018, 12:16:29 AM7/29/18
to TiddlyWiki
Hi, I'm trying to list only the fields in the current tiddler with the value=1

I tried this:

<$list filter='[all[current]fields[1]]'>

</$list>



but it lists all the fields (doesn't change if its [] or [1] or [0])


I searched for examples but couldn't find one where you're not already specifying the name of the field


Thanks,
Dave

Mark S.

unread,
Jul 29, 2018, 12:50:36 AM7/29/18
to TiddlyWiki
Maybe

<$list filter="[all[current]fields[]]" variable="fieldname">
<$list filter="[all[current]get
<fieldname>prefix[1]suffix[1]]">
<
<fieldname>>
</$list>
</$list>

-- Mark

Dave

unread,
Jul 29, 2018, 1:14:42 AM7/29/18
to TiddlyWiki
Ok, so the first list assigns the result of that filter (all fieldnames in the current tiddler) to the variable "fieldname",
and the second list further filters based on that content...

Thanks!

Just wondering though, why would this not work:
<$list filter='[all[current]fields[]prefix[1]suffix[1]]'>

</$list>

? I guess that would look for a field named "1", not containing "1"

So you need 2 layers because in order to "get" the content it has to have the field name already "decided",  is that right?


Dave

unread,
Jul 29, 2018, 2:11:30 AM7/29/18
to tiddl...@googlegroups.com
For the next step I'm trying to use that list of tiddlers to list the data listed in the index("origin") of those data tiddlers

I've tried this:

<$list filter="[indexes[origin]]">

<$list filter="[all[current]fields[]]" variable="fieldname">
<$list filter="[all[current]get
<fieldname>prefix[1]suffix[1]]">
<
<fieldname>>
</$list>
</$list>
</$list>


and this


<$list filter="[all[current]fields[]]" variable="fieldname">
<$list filter="[all[current]get
<fieldname>
prefix[1]suffix[1]]">
<$list filter="[indexes[origin]]">
<
<fieldname>>
</$list>
</$list>
</$list>


the first one doesn't returning anything, and the second one just repeats the initial list you gave me but multiplied (each item repeats for the number of items in the original list)

Are there any tutorials or search terms I should use to find something to get this working? (and I also tried with "index" instead of "indexes")

TonyM

unread,
Jul 29, 2018, 4:05:14 AM7/29/18
to TiddlyWiki
I would reword you first sentence.

Ok, so the first list assigns the result of that filter (all fieldnames in the current tiddler) to the variable "fieldname" a field at a time.

The innerlist is executed once for each field.

Regards
Tony

Mark S.

unread,
Jul 29, 2018, 9:03:33 AM7/29/18
to TiddlyWiki
Hi Dave,

You lost me at "of those data tiddlers". What data tiddlers? The field names just recovered are names of data tiddlers? If so, then maybe:

<$list filter="[all[current]fields[]]" variable="fieldname">
<$list filter="[all[current]get<fieldname>prefix[1]suffix[1]title<fieldname>getindex[origin]]" variable="origin">
<
<fieldname>> == <<origin>>
</$list>
</$list>


I recommend everything tagged with "Filters" at TiddlyWiki.com. Familiarize yourself with [[Filter Operators]] to know what tools are available. Filters remind me of that classic "Waterworks" game, where you're trying to lay out a series of idiosyncratic pieces to arrive at your destination without springing a leak.

Have fun!
-- Mark

Dave

unread,
Jul 29, 2018, 10:26:00 AM7/29/18
to TiddlyWiki
yes, that's perfect - each of the fieldnames were names of data tiddlers.  Thank you!!

And, yes, I have been perusing those filter topics at tiddlywiki.com, but I never thought of/found "getindex".  I'm sure as I learn more the different parts will start making more sense.

At some point in the past I remember seeing a kind of "flow chart" explanation of filters, but I didn't find that last night.  Have you ever come across that?

Dave

unread,
Jul 29, 2018, 10:28:06 AM7/29/18
to TiddlyWiki
Thank you! 

Yeah I've been trying to understand how these nested filters work. 
It seems to start general on the outside and gets progressively specified as you go inwards to the center

Dave

unread,
Jul 29, 2018, 10:38:36 AM7/29/18
to TiddlyWiki
Oh my goodness, it must have been cobwebs. Now that it's morning and I have tiddlywiki.com and a coffee, the first thing I see is Filter Operators > getindex, and Filter Run (the flow chart thingie)

Thanks for your patience!

Mark S.

unread,
Jul 29, 2018, 12:17:57 PM7/29/18
to TiddlyWiki
I think you need to find a way to mark those fields with something different from a number ("1"). Otherwise the first time you need to track a count in a tiddler everything is going to blow up. Maybe different field contents (e.g. "tiddlerlink") or a naming convention (e.g. preface with "pre_")

-- Mark

TonyM

unread,
Jul 29, 2018, 8:58:54 PM7/29/18
to TiddlyWiki
Dave,

You say "start general on the outside and gets progressively specified as you go inwards to the center" which is most likely true but need not be the case.

If the inner list does not make use of something from the outer list it can be a totally "fresh" filter. Of course what it makes use of is commonly the current tiddler changing.

With fields, the has vs the get, often involves an outer and an inner list because one finds the tiddler that has the field in it, the other Gets the value of the field in that tiddler. Thus they cant practically be in the same list operation as the first returns a tiddler name you need, the second returns the value in a field - they are both needed so one filter produces a different result to the other.

One trick often applied is to just try and Get the values on a tiddlers field, if there are none (or no field of that name) nothing will be returned.

Regards
Tony

Dave

unread,
Aug 1, 2018, 9:54:06 PM8/1/18
to TiddlyWiki
Hi, I had some time to start work on this again and realized something's wrong.

If you look at the testResults.png (see attached) it shows that instead of only getting the data from the tiddlers listed as fields with the value "1" (there's only one of them with that value), it just gets them all.

here's the code in question:
<$list filter="[all[current]fields[]]" variable="fieldname">
<$list filter="[all[current]get
<fieldname>prefix[1]suffix[1]title<fieldname>getindex[origin]]" variable="origin">
<
<origin>>
</$list>
</$list>

If I delete out this "prefix[1]suffix[1]", it doesn't change at all

I also tried adding another layer to see if that would solve it:
<$list filter="[all[current]fields[]]" variable="fieldname">
<$list filter="[all[current]get<fieldname>prefix[1]suffix[1]title<fieldname>]" variable="refined">
<$list filter="[all[current]get
<refined>title<refined>getindex[origin]]" variable="origin">
.<
<origin>>.
</$list>
</$list>
</$list>

...but again I get all the data results from the data tiddlers instead of just the ones with "1" in the originating fields (i.e. deleting "prefix[1]suffix[1]" changes nothing)

Any ideas?


testResults.png

TonyM

unread,
Aug 1, 2018, 11:46:04 PM8/1/18
to TiddlyWiki
Dave,

I have not played much with datatiddlers, so cant help too much however

Have you tried to look inside the problem like this

<$list filter="[all[current]fields[]]" variable="fieldname">
fieldname=<<fieldname>><br>

<$list filter="[all[current]get
<fieldname>prefix[1]suffix[1]title<fieldname>]" variable="refined">
refined=<<refined>><br>

<$list filter="[all[current]get<refined>title<refined>getindex[origin]]" variable="origin">
.<<origin>>.
</$list>
</$list>
</$list>


What is your use of title<fieldname> when every filter starts [all[current] (Referring to current tiddler?)

By using a variable on every list, the currentTiddler remains the calling tiddler
As I read it;
The first list returns each fieldname on the current tiddler
The second is trying to get the value of each "named" field as long as it's value is 1? "get<fieldname>prefix[1]suffix[1]"
The third ?
I am not sure you need [all[current] in the last 2 lists and I am not sure what title<fieldname> title<refined> are trying to do when the get is returning the value in a field just before it.

Just another set of eyes

Tony

TonyM

unread,
Aug 2, 2018, 12:00:57 AM8/2/18
to TiddlyWiki
Note: 

Title is a constructor 
  • A few operators ignore their input and generate an independent output instead. These are called selection constructors: they construct an entirely new selection.
is this what you really want?

Tony

Mark S.

unread,
Aug 2, 2018, 1:19:51 AM8/2/18
to TiddlyWiki
Hi Dave,

Tony is right -- there is something funny going on with the "title". It appears that it's not only a constructor, but that it gets invoked even if the filter operators leading up to it should result in the null set.

The following variation worked on my test (but they always work on my test ;-) )

<$list filter="[all[current]fields[]]" variable="fieldname">
<$list filter="[all[current]get<fieldname>prefix[1]suffix[1]" variable="dummy" >
<$list filter="[title
<fieldname>getindex[origin]]" variable="origin">
.<
<origin>>.
</$list>
</$list>
</$list>

The 2nd list statement just uses a dummy variable to avoid setting the <<currentTiddler>> variable. The title of the data dictionary is constructed in the 3rd list and then it's "origin" index pulled out.

Hopefully this will work better --

-- Mark

Dave

unread,
Aug 2, 2018, 12:31:07 PM8/2/18
to TiddlyWiki
thank you both :)

I'll delve into this a little deeper on the weekend, but I did paste Mark's most recent suggestion in and it still returns all the field/datatiddler names instead of just the one's with "1"...  I just confirmed that my TW version is up to date (5.1.17)

Could it be that prefix/suffix only works with actual tiddler names and not field content? (just some amateur wondering)

Mark S.

unread,
Aug 2, 2018, 12:56:34 PM8/2/18
to TiddlyWiki
There was a missing bracket in yesterday's code. Don't know why it didn't throw an error. This works for me on TiddlyWiki.com in a tiddler with a "test1" and "test2" field, of which only "test1" has a "1" and refers to a dictionary tiddler. It only returns a value for field test1:

<$list filter="[all[current]fields[]]" variable="fieldname">
<$list filter="[all[current]get
<fieldname>prefix[1]suffix[1]]" variable="dummy" >
<$list filter="[title
<fieldname>
getindex[origin]]" variable="origin">
<
<fieldname>> .<<origin>>.
</$list>
</$list>
</$list>

Be sure to test the complete code by itself before tweaking it, just so we know what the baseline action is.

Thanks!
-- Mark

Dave

unread,
Aug 2, 2018, 1:12:24 PM8/2/18
to TiddlyWiki
Reply all
Reply to author
Forward
0 new messages