twitter / hogan.js

A compiler for the Mustache templating language
http://twitter.github.io/hogan.js
Apache License 2.0
5.14k stars 431 forks source link

Table parsing is failing #204

Closed viki53 closed 10 years ago

viki53 commented 10 years ago

Hi,

I have a problem with this template:

                {{#solutions.length}}
                <table data-element-id="{{id}}">
                    <thead>
                        <tr>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        {{#solutions}}
                        <tr>
                            <td>{{#fluid}}{{{content}}}{{/fluid}}</td>
                            <td>{{#limit_date}} {{{content}}} {{/limit_date}}</td>
                            <td>{{#prp}}{{{content}}}{{/prp}}</td>
                            <td>{{#availability}}{{{content}}}{{/availability}}</td>
                            <td>{{#security}}{{{content}}}{{/security}}</td>
                            <td>{{#efficiency}}{{{content}}}{{/efficiency}}</td>
                        </tr>
                        {{/solutions}}
                    </tbody>
                </table>
                {{/solutions.length}}

In the <tbody> tag there should be several <tr> filled with the data I provide when rendering. But I only get an empty one instead:

<tbody><tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr></tbody>

I tried removing the condition ({{#solutions.length}} … {{/solutions.length}}) and renaming this list but nothing changes.

I also tested the code on http://trymustache.com/ and it works perfectly there.

Any idea what's wrong ?

viki53 commented 10 years ago

Hi guys, I just found out that the problem appears while parsing the template.

The template HTML becomes this:

        {{#fluid}}{{/fluid}}
                        {{#limit_date}}{{/limit_date}}
                        {{#prp}}{{/prp}}
                        {{#availability}}{{/availability}}
                        {{#security}}{{/security}}
                        {{#efficiency}}{{/efficiency}}
                    <table>
                    <tbody><tr><th>{{{label}}}</th><td>{{{content}}}</td></tr><tr><th>{{{label}}}</th><td>{{{content}}}</td></tr><tr><th>{{{label}}}</th><td>{{{content}}}</td></tr><tr><th>{{{label}}}</th><td>{{{content}}}</td></tr><tr><th>{{{label}}}</th><td>{{{content}}}</td></tr><tr><th>{{{label}}}</th><td>{{{content}}}</td></tr></tbody>
                </table>

Any way I can work around that? I'm supposed to deliver a first version of the app in a few hours so I'd prefer not to change the template engine last minute… :) 

I used different markup instead of a table for now, but that's still something to look into ;)

sayrer commented 10 years ago

Hogan has no knowledge of HTML at all. I think you're being surprised by HTML parsing in general.