Antaris / FuManchu

Handlebars/Mustache templating in .NET
22 stars 12 forks source link

Problem running template inside template #17

Open mattbrailsford opened 8 years ago

mattbrailsford commented 8 years ago

I've created a template like this:

{{#range 1 10}}
  {{#if @index}},{{/if}}
  {
      // Some json content
  }
{{/range}}

I'm using a custom helper for the "range" tag, which all works fine, however there seems to be a problem with the if statement inside it. Running handlebars, rather than getting a list of object tags separated by a comma, I get a bunch of commas all grouped together, then the list of objects next to them (not comma seperated).

,,,,,,,,,{}{}{}{}{}{}{}{}{}{}

I'm trying to debug in at the moment, but it looks to be down to the fact that at some point, the span renderer for the comma renders against the writer that is in the scope, which is the current outer blocks scope, rather than the writer generated for the range helper, thus all the commas get written to the main writer, then on completion of the helper, all the other objects are written to the writer directly afterwards.

I'm currently getting really confused with the visitor rabbit whole to be able to narrow it down to a specific location, but any help would be greatly appreciated.

Antaris commented 8 years ago

Hi @mattbrailsford

Can you share your code for your helper? I'm wondering if it is actually because it is trying to resolve @index but doesn't realise you are creating an enumerable helper. Might need to expand the helper API to allow you to specifiy what the values for @index, @first and @last should be?