【问题标题】:Update value in soy template declared with let更新用 let 声明的大豆模板中的值
【发布时间】:2017-03-02 18:49:16
【问题描述】:

我有一个值与来自我需要在我的大豆模板中显示的配置文件的标志相关联。它是真还是假。

如果为true,则值需要为“x”(例如,但它是一个字符串) 如果为false,则值需要为“”(空)

请注意,我无法从我的配置中传递 true 或 false 值。我也不能省略 false 的值,它必须提供一个空字符串。

我尝试过使用 let 的各种形式的 if 语句,但根据我对文档的解释,无法更改使用 let 声明的值(这没有意义)

这基本上是我需要的:

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

然后我将在我的模板中使用 $myVar。但是,每当我尝试这样做时,都会收到此错误:

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

我能做什么!?

【问题讨论】:

    标签: templates closures conditional google-closure-templates soy-templates


    【解决方案1】:

    使用三元运算符让它工作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-18
      • 2010-10-17
      • 1970-01-01
      • 2016-12-25
      相关资源
      最近更新 更多