Reputation: 869
I'm adding some Javascript to a jade template and the problem I'm having is code duplication because I can't do any jade conditionals inside the script tag. Is there anyway around this, code below.
if streamingType == 'HLS_IOS'
script
:coffee(bare=true)
window.$j = jQuery
window.player = new HtmlPlayer $j('#wrapper')
player._loadVideoAt '#{url}'
else
script
:coffee(bare=true)
window.$j = jQuery
window.player = new FlashPlayer $j('#wrapper'), '#{flashPlayerId}'
player._loadVideoAt '#{url}'`
Upvotes: 4
Views: 1223
Reputation: 12265
You can use conditionals inside script tag in recent jade versions:
script
| window.$j = jQuery;
if streamingType == 'HLS_IOS'
| window.player = new HtmlPlayer($j('#wrapper'));
else
| window.player = new FlashPlayer($j('#wrapper'), '#{flashPlayerId}');
| player._loadVideoAt('#{url}');
Sadly, I didn't find any way to use conditionals and filters at the same time, so you might have to write plain javascript.
Upvotes: 5