View Full Version : Dom Helper Named Parameters in Compiled Templates

18 Oct 2006, 7:57 AM
Do named parameters work with compiled dom templates? I've run the examples using named parameters and included the additional .compile statement but it complains that the parameters aren't defined (for your blog post one, it specifically says id is not defined, which is the first parameter). If you turn off the compile function everything runs smoothly. Using numbered parameters works fine. I ask because the blog post doesn't say that the compiled ones don't support it. It breaks in both IE and Firefox.

If it does support it, I'll post some code to see if it's something I'm doing wrong.

18 Oct 2006, 9:52 AM
Named parameters were added as an afterthought and support for them wasn't added to compiled templates (my mistake). Here's a patch that fixes them:

YAHOO.ext.DomHelper.Template.prototype.compile = function(){
var html = this.html;
var re = /\{(\w+)\}/g;
var body = [];
body.push("this.compiled = function(values){ return ");
var result;
var lastMatchEnd = 0;
while ((result = re.exec(html)) != null){
body.push("'", html.substring(lastMatchEnd, result.index), "' + ");
body.push("values['", html.substring(result.index+1,re.lastIndex-1), "'] + ");
lastMatchEnd = re.lastIndex;
body.push("'", html.substr(lastMatchEnd), "';};");

This will be part of the next release.