Skip to content

Instantly share code, notes, and snippets.

@colelawrence
Created January 7, 2015 17:23
Show Gist options
  • Select an option

  • Save colelawrence/e6316cd41b07a9348d3b to your computer and use it in GitHub Desktop.

Select an option

Save colelawrence/e6316cd41b07a9348d3b to your computer and use it in GitHub Desktop.
Super simple string handlebars formatter
formatString = (string, locals) ->
string.replace /{{([a-zA-Z\.]+)}}/g, (match, value) ->
values = value.split(".")
value = locals
while key = values.shift()
value = value[key]
String value
Say formatString "Hello {{user.name}}", {user:name:"Cole"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment