#each over an array entered in config #1423
-
I'd like to enter an array of [ { "feature":"Price", "description":"The price is set at the checkout" } ] in a text area and then iterate over it in the .hbs file. I can output @config.custom.myArray but not iterate over it. I was assuming {{#each @config.custom.myArray}} but that's not working. Anyone have this working? Thanks, Michael. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Solved: I added a helpers.js file to the root of the theme containing a helper to convert a JSON string to an array :
let themeHelpers = { module.exports = themeHelpers; Then consume the array:
|
Beta Was this translation helpful? Give feedback.
-
Smart Replacer wold do that, yes, pretty useful and thanks for the lead on the template chooser, that I'll use as I was hoping to find a way to hack TinyMCE and that looks like the clean way! |
Beta Was this translation helpful? Give feedback.
Solved:
I added a helpers.js file to the root of the theme containing a helper to convert a JSON string to an array :
`
/*
*/
let themeHelpers = {
deserialize: function (value) {
try {
return JSON.parse(value);
} catch (e) {
console.error(e);
return [];
}
}
};
module.exports = themeHelpers;
`
Then consume the array:
{{#each (deserialize @config.custom.myJsonString)}} {{feature}} {{description}} {{/each}}