Filter a List of Fields by Their Value

77 views
Skip to first unread message

SpennyMcRinghoj

unread,
Aug 18, 2016, 9:49:42 AM8/18/16
to TiddlyWiki
Hi - I'm trying to list a Tiddler's fields by the value that they have, and I'm struggling with it. 


This is what I have currently:

<$list filter=
[is[current]fields[]!regexp[^(text|bag|revision|type|title|modifier|modified|creator|created|draft.title|draft.of|tags)$]] variable="currentField">

<
<currentField>> <$view field=<<currentField>>/>

</$list>


What that shows is the name and value of all fields that the tiddler has, that aren't out of the box (if there's a more graceful way to block these, I'd be grateful).

What I'd like to do, is to filter the list down by checking it's value (if value is "1", then display). Is this possible?



Jed Carty

unread,
Aug 18, 2016, 11:25:28 AM8/18/16
to TiddlyWiki
You can make the filter without the regexp which may be a bit nicer. You can do something like this;

[is[current]fields[]]-text-title-tags-creator-created-modifier-modified-type-bag-revision-draft.title-draft.of

sorting based on field values can be a pain. You can control visibility by something like this:

<$list filter="[is[current]fields[]]-text-title-tags-creator-created-modifier-modified-type-bag-revision-draft.title-draft.of" variable=currentField>

<$list filter='[is[current]get<currentField>prefix[1]]'>


<<currentField>> <$view field=<<currentField>>/>

</$list>

</$list>

The prefix and suffix filters can be much more powerful than they initially seem. Also note that this will check all the fields (aside from the removed ones) for the value.

If you only want to list tiddlers that have a field foo with a value bar it is much simlper you can just do:

<$list filter='[is[current]foo[bar]fields[]]-text-title-tags-creator-created-modifier-modified-type-bag-revision-draft.title-draft.of' variable=currentField>

SpennyMcRinghoj

unread,
Aug 18, 2016, 12:23:45 PM8/18/16
to TiddlyWiki
Yeah, perfect, thanks Jed. One thing I had to do was assign a variable to the inner list in order to show the field value. If I *wanted* to sort (I don't right now) - would that be possible?

<$list filter="[is[current]fields[]]-text-title-tags-creator-created-modifier-modified-type-bag-revision-draft.title-draft.of" variable=currentField>

<$list filter='[is[current]get<currentField>prefix[first]]' variable="innerListField">

<<currentField>> <$view field=<<currentField>>/>

</$list>

</$list>



Thanks again.

Jed Carty

unread,
Aug 18, 2016, 5:33:09 PM8/18/16
to TiddlyWiki
It is possible to sort a list of tiddlers by the values they have in a field using the sort or nsort if you are doing something simple. I was probably a bit pessimistic earlier since I have tried to do some more complex sorting in the past that were rather difficult.
Reply all
Reply to author
Forward
0 new messages