Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7244 closed bug (invalid)

If/Else template tag: Templating attributes results in "unexpected token: else"

Reported by: donabrams@… Owned by: BorisMoore
Priority: low Milestone: 1.5
Component: templates Version: 1.4.3
Keywords: Cc:
Blocked by: Blocking:


For an empty object: {},

Templates that Work:

<div id="{{if something}}{{else}}divid{{/if}}"></div>
{{if something}}<div>{{else}}<div id="divid">{{/if}}</div>

Template that does not work (when it should):

<div {{if something}}{{else}}id="divid"{{/if}}></div>

Change History (7)

comment:1 Changed 8 years ago by donabrams@…

jsFiddle test case: http://jsfiddle.net/87Gxk/5/

comment:2 Changed 8 years ago by jitter

Shouldn't you report this at the following url? http://github.com/jquery/jquery-tmpl/issues

As this seems to be about the jQuery Templates plugin not about jQuery itself

comment:3 Changed 8 years ago by donabrams@…

According to the bug report page:

For jQuery Core or Official jQuery Plugins (i.e. jQuery Templating or Data Linking): This is the right place!

comment:4 Changed 8 years ago by addyosmani

Owner: set to BorisMoore
Status: newassigned

@jitter We're currently accepting tickets regarding the officially supported plugins through Trac so this ticket should be fine. Boris (from MS) will likely follow up.

comment:5 Changed 8 years ago by BorisMoore

This is the wrong way to create templates from strings. $('somestring') requires the string to be HTML, but

<div>{{if something}}<div>{{else}}<div id="divid">{{/if}}two</div></div>, 

for example, is not HTML. And $('somestring') cannot parse somestring as a template. So in fact 2 does not work either. The correct way to do example three would be:

var tmpl3 = $.template(null, '<div if}}="" something}}{{else}}id="divid" {{="" {{if="">three</div>'); 
$.tmpl(tmpl3, {}).appendTo("#tmpl3div"); 

Or simply:

$.tmpl('<div if}}="" something}}{{else}}id="divid" {{="" {{if="">three</div>', {}).appendTo("#tmpl3div");

comment:6 Changed 8 years ago by BorisMoore

Resolution: invalid
Status: assignedclosed

comment:7 Changed 8 years ago by Rick Waldron

Component: unfiledtemplates
Priority: undecidedlow
Note: See TracTickets for help on using tickets.