Chapsterj
Chapsterj

Reputation: 6625

Template method for dojo

When I look in the dojo documentation for template all I get is for dijit and examples only show you been able to use them in a widgit. I'm looking for the equivalent of the below methods in js prototype

var tmpl = new Template(url)
tmpl.evaluate(templateObj)

Does dojo have a template method that you can use in a dojo.declare( class ){} like you can do in js prototype. If not how could I go about similar functionality

Thanks

Upvotes: 2

Views: 338

Answers (2)

Ken Franqueiro
Ken Franqueiro

Reputation: 10559

You may be interested in dojo.string.substitute (you'll need to dojo.require("dojo.string")).

http://dojotoolkit.org/api/dojo/string/substitute

[Edit] Also, if you're interested in acquiring a template for use in substitution from a URL on the same server, you may also want to look into dojo.cache (which is also what is often used to fetch widget templates):

http://dojotoolkit.org/reference-guide/dojo/cache.html

To clarify missingno's response, I don't think dojo.parser is what you're interested in right now; its job is to scan the DOM and transform DOM nodes into widgets and other Dojo components. dijit._Templated only uses dojo.parser when child widgets are involved (i.e. widgetsInTemplate is true); on the other hand, it uses dojo.string.substitute in all cases, to initially parse ${...} strings (e.g. ${id}) in the template.

Upvotes: 3

hugomg
hugomg

Reputation: 69934

I don't know Prototype, but this sounds like dojo.parser stuff. It is what is used by dijit._Templated behind the scenes (you can chack that in the source code if you want...)

Just note that you probably wouldn't need to cal this yourself - there is parseOnLoad=true for automatically parsing your initial HTML.

Upvotes: 0

Related Questions