0

How can I use If statement to specific a variable that is defined in the docpad.coffee file.

I want to do something like this:

<% if sponsor.type == 'Gold': %>
<li class="sponsor-item gold" itemscope itemtype="http://schema.org/Organization">
  <a href="<%= sponsor.url %>" class="sponsor-logo sponsor-link" itemprop="url">
    <img src="<%= sponsor.logo %>" alt="<%= sponsor.name %>" class="photo" itemprop="image">
  </a>
<% else: %>
<li class="sponsor-item" itemscope itemtype="http://schema.org/Organization">
  <a href="<%= sponsor.url %>" class="sponsor-logo sponsor-link" itemprop="url">
    <img src="<%= sponsor.logo %>" alt="<%= sponsor.name %>" class="photo" itemprop="image">
  </a>
<% end %>

This is a code I've made, but he find the string but doesn't add the class "gold" (defined in the li) in the gold sponsor type.

Igo Lapa
  • 1
  • 1

1 Answers1

0

To get variables defined in your template data you must prefix them with the @ character, like so @sponsor -> this translates to this.sponsor in javascript.

This is because template data variables are assigned to the this scope in eco. You can read more about this here: https://github.com/sstephenson/eco#the-context-object

balupton
  • 47,113
  • 32
  • 131
  • 182