Find replace template script

i am trying to implement a very simple find and replace template engine.
I don’t want to use an off the shelf script as i want to be as lean as possible.

i have some json that has values in it that i want to use to replace the tags.
so for example in the json this.whatever would replace {{this.whatever}} in the template.

i want to put a javascript template in script tags with an id to reference it.

i assume i would do an ajax request for the json which i can then loop through.
Then for each value look for it in the template and if it matches replace it.

would this be economical?
would i use regex to look for the braces or is there a better way?

Maybe John Resig’s micro-templating script does what you need?
http://ejohn.org/blog/javascript-micro-templating/
If you are able to write a better one please let us know! :slight_smile:

I’m not trying to write a better one just one that fits my needs. most of the other scripts have logic and mods to them that i won’t need so by stripping it down to what only need itshould be a lot less code.

Thanks for that link it looks good i have been looking at this which might be good too: http://net.tutsplus.com/tutorials/javascript-ajax/create-a-makeshift-javascript-templating-solution/