title: Passing an Array to Handlebars Custom Helper
body: <p>I am trying to pass an array of data to a custom helper with <a href="https://www.npmjs.com/package/express-handlebars" rel="nofollow noreferrer">express-handlebars</a>.  I can't get it to work.</p>
  <p>I can pass in a string and I can pass in an array to an individual view, but I can't seem to pass in an array to a custom helper.  Here is my code:</p>
  <p><strong>String Passed to Custom Helper (this works)</strong></p>
  <pre><code>// app.js
  const hbs = expressHandlebars.create({
    extname: 'html',
    helpers: {
      foo: function () {
        return 'FOO!'
      }
  })
  
  // views/layout/main.html
  &lt;h2&gt;{{ foo }}&lt;/h2&gt;
  
  // Result --&gt; FOO! outputed as expected
  </code></pre>
  <p><strong>Passing an Array to an Individual view (this also works)</strong></p>
  <pre><code>// controllers/pageControllers.js
  exports.getIndexPage = (req, res) =&gt; {
    res.render('index', {
      testList: ['one', 'two', 'three']
    })
  }
  
  // views/index.html
  {{#each testList}}
  &lt;div&gt;{{this}}&lt;/div&gt;
  {{/each}}
  
  // Result --&gt; one, two, three outputted as expected
  </code></pre>
  <p><strong>Array Passed to a Custom Helper (this does NOT work)</strong></p>
  <pre><code>// app.js
  const hbs = expressHandlebars.create({
    extname: 'html',
    helpers: {
      testList2: function () {
        return ['one', 'two', 'three']
      },
    }
  })
  
  // views/layout/main.html
  {{#each testList2}}
    &lt;div&gt;{{this}}&lt;/div&gt;
  {{/each}}
  
  // Result --&gt; NOTHING.  No output, no error messages.
  </code></pre>
  <p>Do custom helpers not take arrays?  The same code works on an individual view.  The same code works for a string on a custom helper.  It just does not work for an array on a custom helper.</p>
  <p>If custom helpers do NOT accept arrays, then how can I get an array of data into my main layout file?  If it does take an array, then what I am doing wrong and how to get this to work?</p>
  <p>Thanks.</p>