0
I created a controller file that has an object with some items being one of them a function that returns files from a folder.
When giving console.log an array is returned with the files from this folder, so far ok! The problem is that I am unable to access this item in the view with Handlebars.
Follows code:
const fs = require('fs')
exports.index = (req, res) => {
let aboutContent = {
pageTitle: 'About',
pageTitleClass: 'about not-home',
files: fs.readdir('./public/assets/img/clients', function(err, files) {
if (err) console.log(err);
else {
// items = {files}
console.log(files);
return files
}
})
}
res.render('about', aboutContent)
}
And in the view I can access normally for example pageTitle so simple {{pageTitle}}, but the item files I’m not getting. Follows below the form I’m trying to:
<ul class="teste">
{{#each files}}
<li>{{this}}</li>
{{/each}}
</ul>