swarr35
swarr35

Reputation: 95

Handlebars lookup to make an href

I am trying to make a mod on an existing app. All I want to do is create an href that contains a url, but using the handlebars lookup function. When I try it just returns a blank value.

Here is my function:

var cardLink = function generateCardLink() {
  var url = `"url/container-scan-reports/${vendor}/${product}/${image}"`        
  return url;      
}

//...

res.render('vendor', { 
  title: 'Vendor Images',
  images: images,
  tags: tags,
  cardLink: cardLink
});

I am then trying to pass in href this way on the top div of template.

<div class="row row-cards-pf ">

{{#each images}}
  <div  href={{lookup ../cardLink @index }} class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
    <div class="card-pf card-pf-view card-pf-view-select card-pf-view-single-select">
        <div class="card-pf-body">
          <div class="card-pf-top-element">
            <span class="pficon-image card-pf-icon-circle"></span>
          </div>
          <h2 class="card-pf-title text-center">
              {{ this }}
          </h2>
          <div class="card-pf-items text-center">
            <div class="card-pf-item">
              {{{ lookup ../tags @index}}}
            </div>
          </div>
       <!--   <p class="card-pf-info text-center"><strong>Most recent image</strong> {{ lookup ../mostRecentImages @index}}</p> -->
        </div>
        <div class="card-pf-view-checkbox">
          <input type="checkbox">
        </div>
      </div>
  </div><!-- /col -->
{{/each}}

Can anyone help me?

Upvotes: 1

Views: 233

Answers (1)

tom
tom

Reputation: 10601

You don't need lookup in this case. I think you want to display the url, so @index is not the right reference. Try it this way:

<div href={{../cardLink}} class="col-xs-12 col-sm-6 col-md-4 col-lg-4">

Upvotes: 1

Related Questions