fluid.stringTemplate and multiple replacement
charly molter
charly.molter at gmail.com
Mon Jul 25 11:51:38 UTC 2011
Hey,
I'm sorry I've just realized that I had forgotten the "%" token this
is now fixed in this commit:
https://github.com/lahabana/infusion/commit/5d2ee45670601263dea49159ed4341a4599276f4
On Mon, Jul 25, 2011 at 10:53 AM, charly molter <charly.molter at gmail.com> wrote:
> Hello,
> Here's my correction I've tried with special characters it works:
> https://github.com/lahabana/infusion/commit/e7e4206f4b0abe727b86ea91ec8682bfccc1475e
>
> Thank you
>
> On Fri, Jun 17, 2011 at 12:27 AM, charly molter <charly.molter at gmail.com> wrote:
>> 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
>>
>
>
>
> --
> Charly Molter
>
--
Charly Molter
More information about the fluid-work
mailing list