Skip to main content

Bug Tracker

Side navigation

#8041 closed bug (invalid)

Opened January 24, 2011 08:02PM UTC

Closed January 24, 2011 08:27PM UTC

Last modified January 28, 2011 01:16PM UTC

jquery.tmpl plugin's tmplItem not returning expected item

Reported by: Owned by: BorisMoore
Priority: low Milestone:
Component: templates Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

If you render a template using an each and then access the dom item (for example in a live/delegate event handler) tmplItem returns the parent data structure as opposed to the desired item in the array:

    items: [
        {num: 1}
//instead of 
    num: 1


Ideally, items inside of {{each}} should be considered nested templates

Attachments (0)
Change History (5)

Changed January 24, 2011 08:16PM UTC by rwaldron comment:1

component: unfiledtemplates
owner: → BorisMoore
status: newassigned

Changed January 24, 2011 08:27PM UTC by BorisMoore comment:2

resolution: → invalid
status: assignedclosed

This is by design.

Under container2 there is only one rendered template instance. {{each}} does not create new nested template instances.

The feature you suggest is already available though, if you want it. Just replace {{each items}} by {{tmpl(items) "#tmpl3"}} with tmpl3 using the content you currently have within the {{each}} tag - <li>${ num }</li>.

{{tmpl}} is for template composition. {{each}} is for iteration within a template without creating sub-templates.

Changed January 24, 2011 09:49PM UTC by comment:3

Thanks for the note on tmpl. Unfortunately, tmpl does not have access to $index in the same way {{each}} does, or at least not in my testing. Is there a way to access index or would this have to be a plugin to the templating system to create a hybrid of the two tags?

Changed January 24, 2011 09:58PM UTC by BorisMoore comment:4

There are a few ways you can work with index in nested templates. See and on reasons why it is not exposed, and some suggested approaches. Also status on whether that feature may later be added to jquery-templates.

Changed January 28, 2011 01:16PM UTC by jitter comment:5

priority: undecidedlow