Bug Tracker

Opened 12 years ago

Closed 12 years ago

#7188 closed bug (fixed)

jQuery.tmpl does not work with DOM fragments

Reported by: istvan.m.antal Owned by: BorisMoore
Priority: undecided Milestone: 1.4.3
Component: templates Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:


$.tmpl('<b>foo</b>',{}); this works, it produces a <b> element

However this does not work: $('<b>foo</b>').tmpl({});

This produces a text node in FF.

Most examples I seen use parented DOM elements, and refer to them by id, but it doesn't seem to work with DOM fragments.

Description: Take the first element in the matched set and render its content as a template, using the specified data.

From this I assume that I is supposed to work with jQuery generated DOM fragments.

Change History (4)

comment:1 Changed 12 years ago by john

Component: unfiledtemplates
Owner: set to dareed
Status: newassigned

comment:2 Changed 12 years ago by BorisMoore

Owner: changed from dareed to BorisMoore

comment:3 Changed 12 years ago by BorisMoore

This is by design. It takes the first matched element as the container of the template, not as the content of the template. This design is necessary, since sometimes you may want multiple top-level elements in the template.

This will work fine: $('<div><b>foo</b></div>').tmpl as will this $('<script id="myTemplate"><b>foo</b></script>').tmpl and that is equivalent to $("#myTemplate").tmpl for a template declared inline.

For multiple top-level elements you can do: $('<div><b>foo</b><b>bar</b></div>').tmpl.

comment:4 Changed 12 years ago by BorisMoore

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.