jimsynz / hamlbars

Some extensions to HAML to allow generation of Handlebars templates.
https://github.com/jamesotron/hamlbars.git
MIT License
179 stars 43 forks source link

Nested conditionals not supported #41

Closed Breefield closed 11 years ago

Breefield commented 11 years ago
{{#if author}}
  {{location.address}}
{{else}}
  {{location.approx_area}}
{{/if}}

This parses as haml prior to handlebars.runtime, so the nesting breaks haml. One can wrap this in :plain, or not nest conditionals. Neither are ideal.

jimsynz commented 11 years ago

Are you using the hamlbars helper?

= hb 'if author' do
  = hb 'location.address'
  = hb 'else'
  = hb 'location.approx_area'
jimsynz commented 11 years ago

Closing since there has been no response.

Breefield commented 11 years ago

Hey James, sorry for not getting back sooner—that works for me :+1:

rpocklin commented 11 years ago

Any reason we have to use the hb helper? I find the {{}} syntax easier to read and type, but it seems there's bug(s) with parsing nested {{handlebars}} statements eg. if conditions and the like.

jimsynz commented 11 years ago

The main reason is that HTML just sees {{}} as text, and won't let you nest text within other text. For example, the following will raise an exception:

{{#each post in controller}}
  {{post.title}}
{{/each}}

Whereas this won't:

=hb 'each post in controller' do
  =hb 'post.title'