Opened 9 years ago

Closed 7 years ago

#16271 closed enhancement (wontfix)

[CLA] Add some utils to include/parse pieces of template at any time

Reported by: iDo Owned by: iDo
Priority: low Milestone: future
Component: Dijit Version: 1.8.1
Keywords: Cc:
Blocked By: Blocking:


The code attach is intended to be used as a mixin. It give you the possibility to parse a template string at any time during the widget life. It allow using attach point, attach event and everything done by the native parser.

Exemples :

var props = {label: "test" };
//parse subTemplate and populate it with props
var node = this.parseTemplate(subTemplate, props);

//parse subTemplate, populate it with props and attach it to the domNode. Position is same as
node = this.parseTemplate(subTemplate, props, this.domNode, 'first');

var items = [
   {label: "test 1" },
   {label: "test 2" }
//parse subTemplate for every items and populate it
var nodes = this.repeatTemplate(subTemplate, items );

//parse subTemplate for every items, populate it and attach it to the domNode. Position is same as
this.repeatTemplate(subTemplate, props, this.domNode, 'first');

Attachments (3)

_RepeaterMixin.js (820 bytes) - added by iDo 9 years ago.
_SplittedTemplateMixin.js (1.4 KB) - added by iDo 9 years ago.
repeaterTest.js (1.3 KB) - added by iDo 9 years ago.

Download all attachments as: .zip

Change History (9)

Changed 9 years ago by iDo

Attachment: _RepeaterMixin.js added

Changed 9 years ago by iDo

Attachment: _SplittedTemplateMixin.js added

comment:1 Changed 9 years ago by bill

Owner: changed from bill to iDo
Status: newpending

Hmm, I'm not sure why you would want something like this. Maybe you can give a bigger example of it being used?

I'm reluctant to add more classes to dijit. I'd be OK with refactoring _TemplatedMixin to expose a static parsing function like your parseTemplate() method, but I don't understand the rhyme or reason for a lot of the stuff your function is doing, like resetting data-dojo-attach-points.

Changed 9 years ago by iDo

Attachment: repeaterTest.js added

comment:2 Changed 9 years ago by iDo

Status: pendingnew

Attachment (repeaterTest.js) added by ticket reporter.

comment:3 Changed 9 years ago by iDo

For exemple, we use it for populating an <ul> with complex <li>. We put the <li> and all of his children in a separate template, then we call repeatTemplate to attach all needed <li> to the <ul>.

The data used to generate the <li> are mostly comming from a web service.

The attach-point is rewritted to add enfore all attach-point to have an unique name (but I agree it's not mandatory).

I attached a test page.

Last edited 9 years ago by iDo (previous) (diff)

comment:4 Changed 9 years ago by bill

OK, thanks for the test page. It's starting to sound like dojox/mvc/Repeat, and also the idea of using mustache or a similar language to support loops and branching in template definitions.

Note also that data-dojo-attach-point is allowed to appear multiple times in a template, and it maps all the attach points into an array of that name.

Anyway, I'll mull this over.

comment:5 Changed 8 years ago by bill

Milestone: tbdfuture
Priority: undecidedlow

comment:6 Changed 7 years ago by bill

Resolution: wontfix
Status: newclosed

Sorry, I don't think there's enough demand for this to add it to dijit.

Note: See TracTickets for help on using tickets.