Filter on Field value

I can filter on Tags OK, but I cannot get the syntax right to filter on a field value, or find any relevant examples in the documentaion wiki.

This works as I expect, giving me a list of links:
<<list-links “[tag[SomeTagName]]”>>

I want to select only a subset of tiddlers that have a field with a particular value, but this does not work:
<<list-links “[field:SomeFieldName|[FieldValue]]”>>

Thanks.

Hard to see, but there’s a stray | in your filter expression that shouldn’t be there.

Sadly the removal of the spurious “|” has no effect and still does not work.

Let me ask the question another way. I want to search a Field for a specific value and list those Tiddlers that match it.

Thanks.

Any unknown filter operator is treated as a field lookup.

Here are some examples:
https://tiddlywiki.com/#field%20Operator%20(Examples)

Your syntax seems correct. My best guess is that you are using field names with upper case characters. They are case sensitive. For example [field:Type[image/png]] wouldn’t find anything, because the field is named type, not Type.

I do have field names beginning with Upper case. Presumably then my search should have Upper case too?

Yes. Names need to match precisely.

Hi, can you explain further as this does not seem to be my situation. I am trying to search a Field for a specific value and list those Tiddlers that match it.

Thanks.

Can you provide a field name and field value from your actual wiki?

Field name: ClassName
Example Field values: English, French, Maths, History

Are they normal tiddlers or shadow tiddlers?

Try this in $:/AdvancedSearch in the Filter tab:

[all[tiddlers+shadows]ClassName[English]]

Does the ClassName field always contain a single option, or would a value like ClassName: English, French be possible? If so, you’ll need the search operator rather than ClassName/field:ClassName, which only returns exact field matches. For instance, to find all non-shadow tiddlers whose ClassName contains “English” (and potentially other values): [search:ClassName[English]]

Ah, that works. Now I think I can see the problem I have. Some of my field values are enclosed in square brackets so they appear as links. Like this [[Chemistry]]

Those don’t work, presumably they need to be escaped in someway or put in quotes?

There is no escape syntax for filters, you will need to refer to the field name via variables.
First define the variable, let’s say as fieldValue and then reference it in the filter as ClassName<fieldValue>

In general it is not recommended to use brackets around field values for presentation purposes, you can control how they are displayed without needing the field value to contain brackets around it.

1 Like

Considering that square brackets have special meanings in wikitext syntax (filters especially), I would attempt to refactor and remove them from field values if possible. A second reason is that by enclosing string values like this, you’re giving them additional special meaning in context of TiddlyWiki, thus overloading the information they carry. I don’t know if there’s a special term for this, but intuitively it makes me want to avoid this. Especially that I consider the hypothetical scenario of working with exported tiddlers content outside of TiddlyWiki. If you know the meaning of the text in a field, just treat it accordingly in the wikitext code that uses it.

As an alternative to search, you can also try using the contains operator instead: it’s intended to work with title lists (i.e space-separated lists with double brackets around multi-word titles), but it will also strip the brackets from its input content, so English and [[English]] will be parsed the same way.

For instance, [contains:ClassName[English]] should find ClassName: English, ClassName: [[English]], and ClassName: [[English]] [[French]] — though it will break on [[English]], because commas are not part of the title-list syntax.

That said, I second @vuk’s advise to keep your wikitext formatting in your tiddler view template, not your field content, for maximum flexibility when filtering. This is intended mostly as a quick workaround if you don’t want to refactor all your fields at this point in time.

OK, I can see from yourself and @vuk I’m not in a good place!

How do I define this variable fieldValue before my filter, or can it prefix the filter itself?

Thankfully I only have single values and no commas, so the contains operator works. Thank you.

There are multiple ways to define variables. Here are some starting points (in order of complexity):

https://tiddlywiki.com/#VarsWidget
https://tiddlywiki.com/#LetWidget
https://tiddlywiki.com/#SetWidget

Note that while in wikitext you reference variables as <<yourVariable>>, in filters you have to use single brackets.

Keep this under your pillow: https://pesky-brackets.tiddlyhost.com

It is a shame that all the help pages for TW are not written as clearly as this!