如何:用于生成HTML的Closure模板,其中元素的属性值包含花括号

时间:2011-09-15 07:02:58

标签: templates google-closure

如何获取使用闭包模板创建的HTML?

<input name="fullName" class="large" type="text" data-validate="{required:true, minlength: 5, maxlength:100, messages:{required:'Please provide your Full Name.', maxlength:'This field can contain maximum 100 characters.'}}"/>

感谢任何帮助。

以下是我迄今为止所尝试的内容。

{namespace myApp.test}
/**
 * Template for UI of Create User View 
 * @param userToEdit It is the object returned from GET on User Resource.
 */
{template .testUser autoescape="false"}
  {{msg desc="<input id=\"fullName\" name=\"fullName\" class=\"large\" type=\"text\" value=\"{$userToEdit.FullName}\" data-validate=\"{required:true, minlength: 5, maxlength:100, messages:{required:\'Please provide your Full Name.\', maxlength:\'This field can contain maximum 100 characters.\'} }\" />"}}
{/template}

返回Malformed attributes in tag错误。


{namespace myApp.test}
/**
 * Template for UI of Create User View 
 * @param userToEdit It is the object returned from GET on User Resource.
 */
{{template .testUser autoescape="false"}}
<input id="fullName" name="fullName" class="large" type="text" value="{{$userToEdit.FullName}}" data-validate="{required:true, minlength: 5, maxlength:100, messages:{required:'Please provide your Full Name.', maxlength:'This field can contain maximum 100 characters.'} }" />
{{/template}}

返回Tag 'template' not at start of line [line 6, column 1].错误。


{namespace myApp.test}
/**
 * Template for UI of Create User View 
 * @param userToEdit It is the object returned from GET on User Resource.
 */
{template .testUser autoescape="false"}
<input id="fullName" name="fullName" class="large" type="text" value="{$userToEdit.FullName}" data-validate="{required:true, minlength: 5, maxlength:100, messages:{required:'Please provide your Full Name.', maxlength:'This field can contain maximum 100 characters.'} }" />
{/template}

返回template .testUser: Left brace '{' not allowed within a Soy tag delimited by single braces (consider using double braces to delimit the Soy tag) [line 7, column 164].错误。


{namespace myApp.test}
/**
 * Template for UI of Create User View 
 * @param userToEdit It is the object returned from GET on User Resource.
 */
{template .testUser autoescape="false"}
<input id="fullName" name="fullName" class="large" type="text" value="{$userToEdit.FullName}" data-validate="{{required:true, minlength: 5, maxlength:100, messages:{{required:'Please provide your Full Name.', maxlength:'This field can contain maximum 100 characters.'}} }}" />
{/template}

返回template .testUser: Double left brace '{{' not allowed within a Soy tag delimited by double braces (consider inserting a space: '{ {') [line 7, column 165].错误。


{namespace myApp.test}
/**
 * Template for UI of Create User View 
 * @param userToEdit It is the object returned from GET on User Resource.
 */
{template .testUser autoescape="false"}
<input id="fullName" name="fullName" class="large" type="text" value="{$userToEdit.FullName}" data-validate="{{required:true, minlength: 5, maxlength:100, messages:{ {required:'Please provide your Full Name.', maxlength:'This field can contain maximum 100 characters.'} } }}" />
{/template}

返回template myApp.test.testUser: Not all code is in Soy V2 syntax (found tag {{print required:true, minlength: 5, maxlength:100, messages:{ {required:'Please provide your Full Name.', maxlength:'This field can contain maximum 100 characters.'} } }} not in Soy V2 syntax).错误。

2 个答案:

答案 0 :(得分:13)

使用Literal Command就像一个魅力。感谢Jim

{namespace myApp.test}
/**
 * Template for UI of Create User View 
 * @param userToEdit It is the object returned from GET on User Resource.
 */
{template .testUser autoescape="false"}
<input name="fullName" value="{$userToEdit.FullName}" class="large" type="text" {literal}data-validate="{required:true, minlength: 5, maxlength:100, messages:{required:'Please provide your Full Name.', maxlength:'This field can contain maximum 100 characters.'}}"{/literal}/>
{/template}

答案 1 :(得分:1)

基于"Special Characters" section in the documentation{lb}{rb}似乎是要走的路。这些将分别将左括号或右括号添加到输出中作为纯文本。