farling42 / obsidian-import-json

Plug-in for Obsidian.md which will create Notes from JSON files
MIT License
85 stars 5 forks source link

Question: Can {{setvar...}} be handed a Helper function to assign value to variable? #71

Closed buttonpushertv closed 3 months ago

buttonpushertv commented 4 months ago

I tried several different methods to get setvar to assign the results of a Helper function to a variable with no success.

In my FMG to Obsidian vault, I have a Helper function like this: getStateName(stateId,allStates). I use it to lookup the State's name from a Burg, where the value is only stored as an ID (number). I tried variations as shown below and none worked:

{{setvar currentStateName getStateName(state,allStates)}} OR {{setvar currentStateName getStateName state allStates}} I also tried: {{setvar currentStateName {{getStateName stateId allStates}}}} OR {{setvar currentStateName {getStateName stateId allStates}}}

None of those worked either.

On a whim, I also tried in a Burg Handlebar template: {{setvar currentStateId state}}

That did not work either. The value just returned as empty. If I pull in the value directly from the state field in the burg element, it comes in correcty. Maybe I'm doing something wrong with assigning the value this way?

farling42 commented 4 months ago

The normal HB syntax is:

{{func1 var1 var2 (func2 var3 var4)}} 

Using () to wrap the inner helper call

buttonpushertv commented 3 months ago

I figured it out.

It was a combination of the missing parentheses and not putting the varName in double quotes.