How to judge wheather two variable equal in spacebar?


#1

here ‘index’ is different on each loop

{{#each proposedVideosList}}
<a href="#" onclick="Session.set('videoNum',{{index}})">     
     <li class="{{#if {{index}}==Session.get('videoNum') }}    // 'index' is changing on each loop,how to judge if index //equal to 'videoNum' ? 
        		did-vote
        	{{/if}}">
        {{index}}
     </li>
</a >
{{/each}}

#2

Hi, you can try this package.
https://atmospherejs.com/raix/handlebar-helpers


#3

it works. thank you…


#4

Yes handlebar-helpers works but perhaps your own helper may be simpler, something like

<li class="{{#if videoNumEquals index  }}    // 'index' is changing
...
videoNumEquals: function(index) {
  return Session.get('videoNum') == index;
}

#5

Me, I use a general comparison helper:

Template.registerHelper 'equals', (a,b) ->
	if a==b then true

and

{{#if equals helper1 helper2}}
   <render_something>
{{/if}