Skip to main content

Bug Tracker

Side navigation

#7244 closed bug (invalid)

Opened October 18, 2010 05:10PM UTC

Closed December 16, 2010 07:24PM UTC

Last modified January 31, 2011 04:54PM UTC

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

Reported by: donabrams@gmail.com Owned by: BorisMoore
Priority: low Milestone: 1.5
Component: templates Version: 1.4.3
Keywords: Cc:
Blocked by: Blocking:
Description

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>
Attachments (0)
Change History (7)

Changed October 18, 2010 05:25PM UTC by donabrams@gmail.com comment:1

jsFiddle test case:

http://jsfiddle.net/87Gxk/5/

Changed October 18, 2010 05:33PM UTC by jitter comment:2

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

Changed October 18, 2010 05:35PM UTC by donabrams@gmail.com comment:3

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!

Changed October 18, 2010 05:44PM UTC by addyosmani comment:4

owner: → 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.

Changed October 22, 2010 05:32PM UTC by BorisMoore comment:5

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");

Changed December 16, 2010 07:24PM UTC by BorisMoore comment:6

resolution: → invalid
status: assignedclosed

Changed January 31, 2011 04:54PM UTC by rwaldron comment:7

component: unfiledtemplates
priority: undecidedlow