Skip to content

Instantly share code, notes, and snippets.

@JeromeDane
Created January 4, 2013 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeromeDane/74c237dc9b98314cb4d9 to your computer and use it in GitHub Desktop.
Save JeromeDane/74c237dc9b98314cb4d9 to your computer and use it in GitHub Desktop.
// Note the addition of if(matches) on line 8 below
replaceVars: function(value, props)
{
if (!value || !props) return value;
var matches = value.match(/{.*?}/ig);
if(matches) {
for(var i = 0, leni = matches.length; i < leni; i++)
{
var match = matches[i];
var matchValues = match.split(/{|}/ig).join("");
value = value.split(match).join(stroep.core.StringUtil.findPropValue(match, matchValues, props));
};
}
return value;
},
//...
@JeromeDane
Copy link
Author

In reference to http://blog.stroep.nl/2012/07/javascript-template-system/.

You need to add a check to see if there are actually any {tag} patterns otherwise the template crashes when no tags are included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment