Skip to content

Instantly share code, notes, and snippets.

@LukeChannings
Last active March 29, 2023 12:45
Show Gist options
  • Save LukeChannings/6173ab951d8b1dc4602e to your computer and use it in GitHub Desktop.
Save LukeChannings/6173ab951d8b1dc4602e to your computer and use it in GitHub Desktop.
A select helper for handlebars
Handlebars.registerHelper("select", function(value, options) {
return options.fn(this)
.split('\n')
.map(function(v) {
var t = 'value="' + value + '"'
return ! RegExp(t).test(v) ? v : v.replace(t, t + ' selected="selected"')
})
.join('\n')
})
@vimtor
Copy link

vimtor commented Jul 19, 2019

Worked like a charm! Thanks.

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