In a Javascript widget, I have a variable query
with arbitrary input from the user. I also have a filter that includes <query>
. What’s the best way to run $tw.wiki.filterTiddlers(filter)
and make sure that <query>
is expanded/transcluded with its value?
My ugly solution (that seems to work) is this,
function makeFakeVariableWidget(name, value) {
return {
getVariable: (_name) => {
if (_name === name)
return value;
else
return "";
}
};
}
var query = "arch";
var fakeWidget = makeFakeVariableWidget("query", query);
var filter = "[search:text<query>]";
$tw.wiki.filterTiddlers(filter , fakeWidget);
makeFakeVariableWidget()
returns an object with only one method, getVariable()
, that only returns a predetermined value for one variable name. After going through $:/core/modules/filters/filter.js, this seems to be the only thing it uses, even though it refers to the object as a “widget”.
I guess that I should use a LetWidget, but how?