I'm trying to access an object (heroImage)passed from my mongodb using handlebars. At the moment I can only get the whole result to show on my page. I'm wanting to extract the url so I can use it in a img src tag.

heroImage (what's displayed when i use {{heroImage}}

{ _id: 5cc4c546feed023a00528f67, 
    slug: 'test',
     name: 'test', __
     v: 0, 
     description: 'test', 
     image: { 
         public_id: 'b0byc2mappz155vixsk9', version: 1556399446, signature: 'bec9125f0421c15c646bcb6f91116cc43032888a', 
         width: 2048, height: 1463, 
         format: 'jpg',
          resource_type: 'image', 
          url: 'http://res.cloudinary.com/', 
          secure_url: 'https://res.cloudinary.com/' 

hbs file, that should be getting the heroImage, and printing its url

{{#if galleries}}
    {{#each galleries}}

        <div class="pull-right text-muted">19th May 2014</div>
    <div class="row gallery-images">
            {{#if heroImage}}
            <div class="col-sm-4 col-md-4 gallery-image1">




<!-- else -->
<h3 class="text-muted">There are no image galleries yet.</h3>

my index.js file, that's looking for the particular heroImage attached to the gallery model

var keystone = require('keystone'),                                                                                                                   
Gallery = keystone.list('Gallery'),                                                                                                               
Image = keystone.list('Image');                                                                                                                   

exports = module.exports = function (req, res) {                                                                                                      

    var view = new keystone.View(req, res);                                                                                                       
    var locals = res.locals;                                                                                                                      

    // locals.section is used to set the currently selected                                                                                       
    // item in the header navigation.                                                                                                             
    locals.section = 'home';                                                                                                                      
    locals.galleries = [];                                                                                                                        

    //Loading the galleries                                                                                                                       
    view.on('init', function(next){                                                                                                               

        var q = Gallery.model.find()                                                                                                              
           .populate('heroImage images')                                                                                                          

           q.exec(function(err, results) {                                                                                                        

               locals.galleries = results;                                                                                               

    // Render the view                                                                                                                            

0 Answers