简体   繁体   English

在 Soy V2 中创建参数的正确方法是什么?

[英]What's the right way to create parameters in Soy V2?

Here is my code:这是我的代码:

{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 */

....

When I try to compile I get an error saying:当我尝试编译时,我收到一条错误消息:

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).`

The only info I've found online seems to suggest this is correct syntax (per Google's site here , per this cheat sheet I found), though, and Googling for "soy v2" has not given me any results that explain what is correct Soy V2 syntax.我在网上找到的唯一信息似乎表明这是正确的语法(根据此处的 Google 网站,根据我找到的这份备忘单),但是,谷歌搜索“soy v2”并没有给我任何结果来解释什么是正确的 Soy V2 语法。

What's the correct way to define these parameters?定义这些参数的正确方法是什么?

It looks like this is the syntax:看起来这是语法:

{namespace test}

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

I also had trouble finding any documentation.我也很难找到任何文档。 I was getting the same errors saying that the {@param ...} syntax is not valid in V2.我收到了同样的错误,说{@param ...}语法在 V2 中无效。 Then I found that the examples for soynode (like this one ) use the comment syntax.然后我发现 soynode 的例子(像这个)使用了注释语法。 Interestingly, it appears that this new syntax does not include a type definition at all, just a var name.有趣的是,这个新语法似乎根本不包含类型定义,只包含一个 var 名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM