Skip to content

Instantly share code, notes, and snippets.

@krusynth
Created April 28, 2013 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krusynth/5477180 to your computer and use it in GitHub Desktop.
Save krusynth/5477180 to your computer and use it in GitHub Desktop.
Handlerbars.js doesn't have proper comparison operators. Also, accessing array indexes is weird.
In your init:
/* Handlebars doesn't have the basics. */
Handlebars.registerHelper('ifEq', function(v1, v2, options) {
if(v1 == v2) {
return options.fn(this);
}
return options.inverse(this);
});
In the template:
{{! Undocumented: to access an array element by index in Handlebars,
use dot syntax instead of brackets. }}
{{#ifEq this.incident.media.0.media_type 'Video'}}
<video id="incident-video" class="video-js vjs-default-skin" autoplay
preload="auto" width="640" height="264" autoplay
data-setup='{"techOrder": ["html5","flash"]}'>
<source id="videoSource1"
src="{{ this.incident.media.0.file_location }}"
type="video/mp4"
/>
</video>
{{/ifEq}}
@jasonsee
Copy link

wat?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment