Friday, 17 March 2017

How to nest each statements with single dimensional arrays? (handlebars/node.js)

I'm trying to loop through one array to create a series of columns, and then in each column populate a select menu with a list of images.

Here is the code I'm using to render the view;

 var text = ['one', 'two', 'three']
 var imgs = ['img1.png', 'img2.png', 'img3.png']

 res.render('validate', {test: text, images: imgs});

And the handlebars code;

<div class="column-container">
    
        <div class="column">
            <h1></h1>

            <select>
                
                    <option value=""></option>
                
            </select>
        </div>
    
</div>

When running this code, the first each statement is the only one recognised, and the select menu's in each column return empty.

First time using a template engine, so not sure if the each helper is intended to be used this way?



via pdiddy

No comments:

Post a Comment