Created
April 28, 2013 15:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wat?