Last active
August 5, 2024 20:15
-
-
Save LukeChannings/6173ab951d8b1dc4602e to your computer and use it in GitHub Desktop.
A select helper for handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worked like a charm! Thanks.