fluid.stringTemplate and multiple replacement
charly molter
charly.molter at gmail.com
Thu Jun 16 23:27:10 UTC 2011
Hello,
I'm currently using the stringTemplate function on a template like
that "<%tag %classes %attributes >%content </%tag >" my problem is
that it doesn't do the multiple replacement of %tag after checking the
code:
fluid.stringTemplate = function (template, values) {
var newString = template;
for (var key in values) {
var searchStr = "%" + key;
newString = newString.replace(searchStr, values[key]);
}
return newString;
};
It seems quite obvious that it doesn't do it. However I think this is
a lack, you expect from this kind of function to replace every
occurrences of a similar token.
So please tell me if there's something I've missed to use it that way...
Otherwise after looking for a little bit I've found that enhancement
that would enable to do that:
fluid.stringTemplate = function (template, values) {
var newString;
var tmpString = template;
for (var key in values) {
var searchStr = "%" + key;
do {
newString = tmpString;
tmpString = newString.replace(searchStr, values[key]);
} while(tmpString !== newString);
}
return newString;
};
So what do you think about it? Am I the only one thinking that the
replacement in a template should be repetitive?
--
Charly Molter
More information about the fluid-work
mailing list