[TW5] List filter help

227 views
Skip to first unread message

Jon

unread,
Apr 7, 2015, 2:44:01 AM4/7/15
to tiddl...@googlegroups.com
Hi

I want to display tag pills for tiddlers which are tagged with tag 1 but exclude tags 2 to 8 from appearing in the list.

The following will exclude tag2 from the display and I could exclude the others in the same way but I'm sure there's a more elegant way of doing it.

<$list filter="[tag[tag1]!tag[tag2]tags[]sort[title]]">
<$transclude tiddler="$:/core/ui/TagTemplate"/>
</$list>

If I assigned a field value to tags 2 to 8, I thought I could exclude them that way, but I can't work out how to do it.

I tried this amongst other things, but it doesn't work

<$list filter="[tag[tag1]!has[fieldname]tags[]sort[title]]">
<$transclude tiddler="$:/core/ui/TagTemplate"/>
</$list>j


Any ideas?

Thanks,
Jon

Jed Carty

unread,
Apr 7, 2015, 1:16:10 PM4/7/15
to tiddl...@googlegroups.com
Is the field empty? If it is that may be the problem.

Jon

unread,
Apr 7, 2015, 3:55:01 PM4/7/15
to tiddl...@googlegroups.com
Hi Jed,

I've double checked and there is a value in the field (of the tag tiddler)

I suspect it might be the expression at fault because nothing happens if
!has[fieldname] is changed to !has[]

Anyway, sounds like I'm on the right tracks at least.


Regards
Jon

RichardWilliamSmith

unread,
Apr 8, 2015, 6:09:26 PM4/8/15
to tiddl...@googlegroups.com
Hi Jon,

I don't quite understand what you're trying to do.... you just want one list and you want it to contain the tagpill for 'tag1' once?

Do you only want it to appear once or once for each tiddler that has it (but doesn't have the other tags?) - do you want to list the tiddlers or just the tagpill? Isn't this the same as just listing the 'tag1' pill regardless of anything else? like...

<$list filter="[[tag1]]">

<$transclude tiddler="$:/core/ui/TagTemplate"/> 
</$list>

The reason this

<$list filter="[tag[tag1]!has[fieldname]tags[]sort[title]]">
<$transclude tiddler="$:/core/ui/TagTemplate"/> 
</$list>

doesn't work is because it's finding all the tiddlers that have tag1 and then discarding the ones that have 'fieldname' (none of them because you put that field on the tag-tiddlers, not the tiddlers themselves) and then listing all the tags and then sorting them.

I suspect what you're after (which I don't quite get - is it for a template?) can be done by nesting the filter expressions, something like this

<$list filter="[tag[tag1]]">
<$list filter="[is[current][tag1]]">

<$transclude tiddler="$:/core/ui/TagTemplate"/> 
</$list>
</$list>

Let me know if I'm close and I'll help you figure it out. 

Regards,
Richard

Jon

unread,
Apr 9, 2015, 3:26:05 AM4/9/15
to tiddl...@googlegroups.com
Hi Richard,

Thanks for taking a look at this.

Lets say I have a list of animals which are each tagged according to their class, so "mammal", "bird", "insect" etc. and then another tag to define the no. of legs. (OK, so I'm not a taxonomist!)

So human would be tagged with "animal", "mammal" and "2 legs"

if I use

<$list filter="[tag[animal]tags[]sort[title]]">

<$transclude tiddler="$:/core/ui/TagTemplate"/>
</$list>


it will display all the tag pills, so "animal", "fish", "reptile", "8 legs" etc. and clicking on each will show the names of the animals contained in that category.

What I'd like to do is separate the list of tag pills, so for instance, one list would show the class of animal and the other the number of legs.

I haven't done a mock up of this so I do hope this is an accurate translation of my use case and that it also makes sense.

As I mentioned, I can subtract the individual tags of the category from the expression like so:

<$list filter="[tag[animal]!tag[2 legs]tags[]sort[title]]">

<$transclude tiddler="$:/core/ui/TagTemplate"/>
</$list>

but wondered if I could do it by excluding a field value which is assigned to one of the categories.

From what you've said I understand why my original idea doesn't work. Could you explain the nested idea and particularly how this is generally used?


 <$list filter="[is[current][tag1]]">

Thanks,
Jon

Richard Smith

unread,
Apr 9, 2015, 4:54:10 AM4/9/15
to tiddl...@googlegroups.com
Hi Jon,

I get it now, thanks - so the issue is how to keep track of which tags belong to which set-of-tags. You can use tags for that too, by tagging the tag-tiddlers. So the tiddlers mammal, reptile etc. are tags themselves and their corresponding tag-tiddlers are each tagged with 'class' to indicate that these tags belong to the set-of-tags 'class'. Then you can list the class-tags like this

<$list filter="[tag[animal]tags[]tag[class]]">

<$transclude tiddler="$:/core/ui/TagTemplate"/> 
</$list>


Regards,
Richard

PS: I was initially tempted to suggest using a separate field for each of these sets-of-tags. Although you may have to re-create some of the tag-like behaviour, I think it gives you much nicer record-structure in the end - I suppose it depends how big/serious your project is.

Jon

unread,
Apr 9, 2015, 4:14:42 PM4/9/15
to tiddl...@googlegroups.com
Hi Richard,

That worked perfectly!

Many thanks
Jon
Reply all
Reply to author
Forward
0 new messages