Ticket #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: | ||
| Blocking: | Blocked by: |
Description
$.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
comment:1 Changed 3 years ago by john
- Owner set to dareed
- Status changed from new to assigned
- Component changed from unfiled to templates
comment:3 Changed 3 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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
