How can I make this ViewTemplateBodyFilter query work appropriately

I’m trying to handle a certain subset of missing tiddlers with a ViewTemplateBodyFilter. I have successfully done so before with something like this:

title: $:/_/bb/config/ViewTemplateBodyFilters/card
tags: $:/tags/ViewTemplateBodyFilter

[prefix[Card_]then[$:/_/bb/templates/bingo-card]]
title: $:/_/bb/templates/bingo-card

<$let card={{{ [<currentTiddler>removeprefix[Card_]] }}}>
<!-- build my interface using `card` -->
</$let>

But that used the title as the input to the filter run. The way I know to do this for my current project would require the title elsewhere in the filter. What I’m trying looks like this:

Warning: broken code!

title: $:/_/sql/config/ViewTemplateBodyFilters/country
tags: $:/tags/ViewTemplateBodyFilter

[all.countries[]match<currentTiddler>then[$:/_/sql/templates/Country]]
<!--                  ^^^^^^^^^^^^^^       -->

I was assuming that the title would be passed as currentTiddler. But it’s not happening. Or something else is going wrong. Is there a straightforward way to rewrite this filter?

Note that all.countries is collecting a list of countries known elsewhere in the wiki:

\function all.countries() [tag[Customer]get[country]] [tag[Supplier]get[country]] +[unique[]sort[]]

That’s working properly.

<$list filter="France Brazil Ecuador Russia USA" >
  <li>{{{ [all.countries[]match<currentTiddler>then[yes]else[no]] }}}</li>
</$list>

properly returns yes, yes, no, no, yes.

I’m pretty sure that this means that my hope/assumption – that currentTiddler would include the title of the missing tiddler – is simply wrong.

Can you suggest another way I can write this cascade step?

You can access the input title within a cascade with all[].

Try these:
[all[]] :intersection[all.countries[]] :then[[$:/_/sql/templates/Country]]

[all[]] :filter[all.countries[]match<currentTiddler>] :then[[$:/_/sql/templates/Country]]

Do make sure the view template body filter is before the default view template in the tag order. (Add the field list-before with value $:/config/ViewTemplateBodyFilters/default to the tiddler $:/_/sql/config/ViewTemplateBodyFilters/country)

Thank you. For whatever reason, neither of these seems to do it for me. I’ve posted the wiki to http://scott.sauyet.com/Tiddlywiki/Issues/ttw10130/ if you (or anyone else!) has a few minutes to investigate why these aren’t working. I’m guessing it’s just a silly typo or some such, but I’ve been starting for a while without any insights.

Yes, thanks. That’s bitten me often enough that I do tend to double-check. One question about this: Is there any general guidance about when it’s better to use list-before versus dragging and dropping in the Tag dropdown to edit its list field? I tend to do the latter unless it’s a tiddler I expect to share across wikis. It’s a bit quicker to do. But I may be missing good reasons to use list-before.

First, I found that this works, as a cascade condition (just pulling things over from your function, omitting sort and unique, reframing as one long filter run focused on storyTiddler rather than currentTiddler):

[[Customer,Supplier]split[,]tagging[]get[country]match<storyTiddler>then[$:/_/sql/templates/Country]]

From there, I confirmed that your whole initial setup (including your function-based cascade) works if you simply reframe the custom function this way:

\function all.countries() [[Customer,Supplier]split[,]tagging[]get[country]unique[]sort[]]

Perhaps there’s something about getting the function into just one compound filter run? Or something about pivoting on storyTiddler (which just seems a fine choice for most empty-node template solutions, and avoids getting swept up in the filter’s own currentTiddler logic).

1 Like

Your filter runs in the function need to start with all[tiddlers] to explicitly include all tiddlers, otherwise the only operate on the input to the function (which in this case is a single title).

I personally prefer to always use the list-before field to reduce the chance that I’ll run into unexpected problems one day because another plugin reset the tag tiddler order or that I decided to move the functionality to another wiki.

@springer good call on using the storyTiddler variable to simplify the filters! I don’t use default templates and thus tend to forget that the variable exists.

1 Like

Thank you. I suddenly have a wealth of working options! I know that in the dim murky days—you know, a year or so ago!—I saw storyTiddler and attempted to file it away for when I needed it. Obviously, I failed.

Thank you. This makes sense. While I’m not at all wedded to having that function, it simply worked elsewhere, and I couldn’t make sense of why it didn’t in this context.

I did consider that, but it didn’t seem likely when it worked other places I needed it. Saq’s explanation makes it clear. It only works because I’ve been using it always as the initial run.

Ahh, that explains everything. Thank you very much!

Makes sense. Thank you.


Now to try to figure out which of the many good options I’ve been given to actually use. Thank you both!

1 Like

Again, thank you everyone for your help. I discussed this fix in my post on the new version. This is working quite well now.

1 Like