【问题标题】:What's the right way to create parameters in Soy V2?在 Soy V2 中创建参数的正确方法是什么?
【发布时间】:2019-04-29 23:59:49
【问题描述】:

这是我的代码:

{template .someTemplate}
    {@param? icon : string} /** CSS class that loads and styles the icon */
    {@param? headlineHtml : any} /** Headline text with optional html for styling */
    {@param? textHtml : any} /** Subtext with optional html for styling */
    {@param? buttonText : string} /** The call to action text for the button */
    {@param? rejectButtonText : string} /** The text for choosing to reject the call to action */

....

当我尝试编译时,我收到一条错误消息:

Exception in thread "main" com.google.template.soy.base.SoySyntaxException: In file ./myfile.soy:7, template com.namespace.someTemplate: Not all code is in Soy V2 syntax (found tag {@param? icon : string} not in Soy V2 syntax).`

我在网上找到的唯一信息似乎表明这是正确的语法(根据Google's site here,根据我发现的this cheat sheet),但谷歌搜索“soy v2”并没有给我任何解释什么的结果是正确的 Soy V2 语法。

定义这些参数的正确方法是什么?

【问题讨论】:

    标签: google-closure-templates soy-templates


    【解决方案1】:

    看起来是这样的语法:

    {namespace test}
    
    /**
     * This is a template.
     * @param name The name to say hello to
     */
    {template .main}
    Hello {$name}
    {/template}
    

    我也很难找到任何文档。我遇到了同样的错误,说 {@param ...} 语法在 V2 中无效。然后我发现 soynode 的示例(如this one)使用注释语法。有趣的是,这个新语法似乎根本不包括类型定义,只是一个 var 名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-01
      • 2015-05-22
      • 2014-08-28
      • 2012-12-28
      • 2013-03-02
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      相关资源
      最近更新 更多