Skip to main content

Bug Tracker

Side navigation

#7188 closed bug (fixed)

Opened October 14, 2010 11:19AM UTC

Closed October 14, 2010 06:28PM UTC

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

Attachments (0)
Change History (4)

Changed October 14, 2010 01:24PM UTC by john comment:1

component: unfiledtemplates
owner: → dareed
status: newassigned

Changed October 14, 2010 06:14PM UTC by BorisMoore comment:2

owner: dareedBorisMoore

Changed October 14, 2010 06:27PM UTC by BorisMoore comment:3

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.

Changed October 14, 2010 06:28PM UTC by BorisMoore comment:4

resolution: → fixed
status: assignedclosed