开发者

How To: Closure Template for generating HTML in which attribute value of an element contains curly braces

How do I get following HTML created using closure template?

<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.'}}"/>

Any help is appreciated.

Below is what I have tried till now.

{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}

Returns Malformed attributes in tag error.


{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}}

Return Tag 'template' not at start of line [line 6, column 1]. error.


{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}

Returns 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]. error.


{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}

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


{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}

Returns 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). error.


Using Literal Command worked like a charm. Thanks to 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}


Based on the "Special Characters" section in the documentation, {lb} and {rb} seem to be the way to go. These will add a left brace or right brace, respectively, to your output as plain text.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜