Using $setmultiplevariables widget and the complex else condition

Folks,

I am yet to master the setmultiplevariables widget and hope someone could help me;

See this code snippit

<$setmultiplevariables 
$names="[enlist{$:/config/active-modes}]" 
$values="[enlist{$:/config/active-modes}] :map[<..currentTiddler>get<currentTiddler>]">
<hr>
design-mode=<<design-mode>>
</$setmultiplevariables>

In the above a list of fieldnames is found in the $:/config/active-modes tiddler.

This is designed to set a variable of the same name to the value of the fieldname found in the current tiddler.

In the above case my tiddler had a field called design-mode equal to yes, with design-mode=<<design-mode>>returning design-mode=yes.

However I would like the above setmultiplevariables widget to do the following if there is no fieldname in the current tiddler (or it has no value).

I have no idea how to do it, and I have tried.

If the fieldname does not have a value, I would like to add the prefix “$:/config/” to that field name and return the content of that tiddler title, setting in the variable (also named the same as fieldname).

Purpose:
I want a variable set for each of the named fieldnames, first attempting to get the value from a field of that name on the current tiddler and setting the variable to the value found there.

If there is no local / current Tiddler field I want to get the value from the config tiddlers text field instead.

Any advice warmly welcomed.

You can use a multi-run filter expression for the mapping using the subfilter operator. Something along these lines:

<$let mappingFilter="[<..currentTiddler>get[<currentTiddler>] :else[<currentTiddler>lookup[$:/config/active-modes]]">
<$setmultiplevariables 
$names="[enlist{$:/config/active-modes}]" 
$values="[enlist{$:/config/active-modes}] :map[subfilter<mappingFilter>]">
<hr>
design-mode=<<design-mode>>
</$setmultiplevariables>
</$let>
1 Like

Thanks @saqimtiaz

Is this because of a limitation of setmultiplevariables or map?

I would say neither. It is a limitation of the conditional logic you can express in a single filter run with the core filter operators.

A limitation easily overcome with the subfilter which comes to the rescue sometimes.

It would be nice to find a way to spell it out and add it to the doco.

Thanks a lot.

If anyone is passing the ultimate solution is here;

<$let mappingFilter="[<..currentTiddler>get<currentTiddler>] :else[[$:/config/]addsuffix<currentTiddler>get[text]]">
<$setmultiplevariables 
$names="[enlist{$:/config/active-modes}]" 
$values="[enlist{$:/config/active-modes}] :map[subfilter<mappingFilter>]">

;Inside the setmultiplevariables 

<$list filter="[variables[]suffix[-mode]]" variable=mode-variable>
<<mode-variable>> {{{ [<mode-variable>getvariable[]] }}}<br>
</$list>
</$setmultiplevariables>
</$let>

I will update here with a link when I have something that makes use of this.