0

I have a conundrum here, and I apologize for not being able to just copy and paste code as it's internal corporate stuff. I'll try to explain the best I can without showing code.

Let's say I have a Handlebars page full of HTML and some light logic ({#if} statements). The thing is, there are a LOT of if/else/etc statements interspersed between HTML bits. This is probably fine except for the fact that within an each loop, I now have to introduce some logic that is beyond what Handlebars will allow (basically I need to check the index of the current iteration of the loop [if index > 4 then..]). So now I have to code my logic into a Handlebars helper, but I also have to bring all the HTML into the helper code now! e.g.:

if @isSomeVar?
  output += '<p class="something">'
else
  output += '<p class="something-else" data-stuff="Some Data">'

output += if @myVar? then @myVar else 'A hardcoded string'
output += '</p><div class="info">'

So because Handlebars is logicless because it wants to remain clean, I have to move HTML into my .coffee code, which kinda defeats the whole purpose of separating code & presentation!

What in the world is my solution here?

CaptSaltyJack
  • 15,283
  • 17
  • 70
  • 99
  • Because there are tons of conditionals I have to check throughout the code. I don't see how to make this code look clean. I'm either going to have lots of conditionals in my .hbs file, or lots of HTML in my .coffee file. – CaptSaltyJack Sep 26 '13 at 21:06
  • Could you use a different template system? http://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more – hpaulj Sep 27 '13 at 04:03
  • @hpaulj I can't just change it, no. I'm on a huge team. But really this question is about any logicless templating system, not just Handlebars. I don't see how one can truly separate presentation from logic 100%. – CaptSaltyJack Oct 01 '13 at 16:58

0 Answers0