Update value in soy template declared with let

2.1k Views Asked by At

I have one value that is tied to a flag that comes from a config file that I need to show in my soy template. It is either true or false.

If true, the value needs to be "x" (for example, but it is a string) If false, the value needs to be "" (empty)

Notice that I cannot pass in the true or false value from my config. I also cannot omit the value on false, it has to supply an empty string.

I've tried various forms of if statements using let, but according to my interpretations of the docs, a value declared with let cannot be changed (which doesn't make sense)

This is basically what I need:

{if $inputValue.value == 'true'}
    {let $myVar: ($someValueThatExistsInMyTemplate) /}
{else}
    {let $myVar: '' /}
{/if}

Then I will use $myVar in my template. However, whenever I try that, I get this error:

Found references to data keys that are not declared in SoyDoc: [myVar]

What can I do!?

1

There are 1 best solutions below

0
On

Got it working using the ternary operator:

{let $dataParent: ($item.preferences.accordionOnOff.value == 'true') ? ($item.name) : '' /}