Variables in list filters

311 views
Skip to first unread message

Reece Shaw

unread,
Feb 28, 2019, 12:58:14 AM2/28/19
to TiddlyWiki
Hey All,

I'm currently working on additional features for a campaign/world manager wiki. I'm fond of having dynamic lists that generate based on what the user puts into the wiki. I've run into the below issue:

I have a group of tiddlers tagged "Location" and a group of tiddlers tagged "Faction". The Location tiddlers contain a field titled "faction-dominant" that always contains the title of a single Faction tiddler.

SO in order to maintain consistency I have a "footer" template that is a foldable reveal. I'd like this footer to only display the Location tiddlers where faction-dominant has a value that matches the title of the tiddler that holds the filter. 

To further complicate things, the filter must first pass the title to a system tiddler where I am storing the fields for editing purposes. The code:

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


<$list filter= "[[$:/]addsuffix[state]addsuffix[/]addsuffix{!!title}]">


<$list filter= "[has:field[faction-dominant]]">


</$list>
</$list>
</$list>

I've tried $set and $vars but I am having trouble parsing what exactly I need to set where and documentation is a bit out of my scope of understanding as someone who isn't a trained coder. Any advice?

Thanks,
-Reece

example location.png

S. S.

unread,
Feb 28, 2019, 2:35:25 AM2/28/19
to TiddlyWiki
Hello Reece,

It's a little difficult to understand your requirements the way you phrased it. I could not understand what is meant by "the title of the tiddler that holds the filter" - which filter? The one pasted below? What do you want that tiddler to do?

Anyway to get you started - If you have:

A Tiddler:
title: A Location Tiddler
tag: Location
faction-dominant: A Faction Tiddler

Another Tiddler:
title: A Faction Tiddler
tag: Faction

Put this in the tiddler: A Faction Tiddler
<$list filter="[has[faction-dominant]] +[faction-dominant{!!title}]">

</$list>

It will only list tiddlers whose faction-dominant field contains the title of the tiddler this code is in, in this case: A Faction Tiddler

If you could try to explain your issue again in a different way, it may be easier to understand.

Also the code you pasted - it's difficult to understand what you ware trying to do - still it might be improved - you could try this:
[tag[Location]sort[tags]] - the sort here is, I think, a little meaningless. Perhaps you meant:
[tag[Location]sort[]]

[[$:/]addsuffix[state]addsuffix[/]addsuffix{!!title}] may be better written as:
[[$:/state/]addsuffix{!!title}]

[has:field[faction-dominant]] will also find tiddlers that have this faction-dominant field but it is empty.
[has[faction-dominant]] will only find tiddlers where this faction-dominant field is NOT empty

Regards

Reece Shaw

unread,
Feb 28, 2019, 8:41:43 PM2/28/19
to TiddlyWiki
Hey S. S.,

Apologies for the confusion... I posted this at 1 AM local and my sleep deprivation got the best of me so that I pasted the wrong filter in from a backup test I had.

I have THREE tiddlers.

Tiddler A: "UI" tiddler tagged "Location"
Tiddler B: a system tiddler that contains the data fields for the UI display of [A] (faction-dominant field with {{A!!title}} as the value)
Tiddler C: "Faction" tiddler

The list filter is a footer that will be housed in [C]. The intended function is for the footer to display only [A] tiddlers that have an associated [B] tiddler that has Field(faction-dominant) and where (faction-dominant) has value={{C!!title}}

I've attached the wiki itself because this may make more sense in context, below is the beginning of the filter. 

<$list filter="[tag[Locationj]]">
<$list filter="[[$:/world/location/]addsuffix{!!title}]">

</$list>
<$/list>





On Thursday, February 28, 2019 at 2:35:25 AM UTC-5, S. S. wrote:Hello Reece,
notes-nonencrypted.html

Reece Shaw

unread,
Feb 28, 2019, 10:51:52 PM2/28/19
to TiddlyWiki

S. S.

unread,
Mar 1, 2019, 1:20:47 AM3/1/19
to TiddlyWiki
Reece,

Maybe using a filter like this in your footer would work:

<$set name="title-remove-prefix" filter="[{!!title}removeprefix[$:/world/faction/]]">
<$wikify name="fixed-title" text=<
<title-remove-prefix>>>
<$list filter="[faction-dominant
<fixed-title>removeprefix[$:/world/location/]]">

</$list>
</$wikify>
</$set>

The complication is that having used multiple templates, the {{!!title}} in the footer pointed to a changed prefixed title.
The first $set removes the prefix.
The $wikify changes it to rendered text.
The $list looks for tiddlers that have that "original" {{!!title}} in their faction-dominant field, then strips the prefix - which gives the tiddler tagged "Location"

Hope that works!

Regards!

Reece Shaw

unread,
Mar 3, 2019, 9:51:54 PM3/3/19
to TiddlyWiki
This worked perfectly! I also better understand how sets work, and on top of that I didn't realize there was a removeprefix operator. Thanks so much! I think I can apply this in a few other ways as well...

-Reece

S. S.

unread,
Mar 3, 2019, 11:45:06 PM3/3/19
to TiddlyWiki
Reece,

You actually made implementation much smoother by your naming structure, by choosing meaningful tiddler titles of System tiddlers templates (and other data tiddlers) with the right suffixes - such as the names of tiddlers and tags they relate to. As you can see by the simplicity of the code that works, these choices you made makes both coding and debugging much easier.

Glad the nut was successfully cracked, and hope you have a productive outcome!

Regards
Reply all
Reply to author
Forward
0 new messages