I am designing a site using node, handlebars and express and can't figure out why a widget isn't working.
This is in my partials directory which is a subdirectory of views- called weather.handlebars
<div class="weatherWidget">
{{#each partials.weather.locations}}
<div class="location">
<h3>{{name}}</h3>
<a href="{{forecastUrl}}">
<img src="{{iconUrl}}" alt="{{weather}}">
{{weather}}, {{temp}}
</a>
</div>
{{/each}}
<small>Source: <a href="http://www.wunderground.com">Weather underground</a></small>
</div>
This is the function and middleware in the main js file
function getWeatherData(){
return{
locations: [
{
name: 'Portland',
forecastUrl: 'http://www.wunderground.com/US/OR/Portland.html',
iconUrl: 'http://icons-ak.wxug.com/i/c/k/cloudy.gif',
weather: 'Overcast',
temp: '51.1 F (12.3 C)',
},
{
name: 'Bond',
forecastUrl: 'http://www.wunderground.com/US/OR/Bend.html',
iconUrl: 'http://icons-ak.wxug.com/i/c/k/partlycloudy.gif',
weather: 'Partly Cloudy',
temp: '55.0 F (12.8 C)',
},
{
name: 'Manzanita',
forecastUrl: 'http://www.wunderground.com/US/OR/Manzanita.html',
iconUrl: 'http://icons-ak.wxug.com/i/c/k/rain.gif',
weather: 'light rain',
temp: '55.0 F (12.8 C)',
},
],
};
}
//middleware to inject data into res.locals.partials object
app.use(function(req, res, next){
if(!res.locals.partials) res.locals.partials = {};
res.locals.partials.weather = getWeatherData();
next();
});
And this is the widget call in home.handlebars which is in the views directory
<h1>Heading</h1>
<!-- Weather Widget in a View using handlebars markup > is how to include a partial in a view -->
{{> weather}}
The only thing that is displayed is Source Weather underground so it appears that the widget info isn't being loaded. Any ideas?