Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template with table not gets rendered, otherwise does. #680

Closed
sachingutte opened this issue Dec 20, 2013 · 4 comments
Closed

template with table not gets rendered, otherwise does. #680

sachingutte opened this issue Dec 20, 2013 · 4 comments

Comments

@sachingutte
Copy link

I've this data -

var data = [{
    "subject_name": "PCD",
}, {
    "subject_name": "DAA",
}];

Handlebar does render above data into following template-

{{#each subjects}}
        <li>{{subject_name}}</li>
{{/each}}  

But when I try to use tables, it does not load it. I used {{#each}} to loop through data but it directly goes to {{else}} section.

<table class="table">
        {{#each subjects}}
            <tr>
                <td>{{subject_name}}</td>
            </tr>
        {{else}}
            <tr>
                <td>No subjects added.</td>
            </tr>
        {{/each}}
 </table>

Here's complete code for test case -

<div id="subjectList" class="hidden">
    {{#each subjects}}
        <li>{{subject_name}}</li>
    {{/each}}   
    <table class="table">
        {{#each subjects}}
            <tr>
                <td>{{subject_name}}</td>
            </tr>
        {{else}}
            <tr>
                <td>No subjects added.</td>
            </tr>
        {{/each}}
    </table>
</div>
<div id="app"></div>

and javascript -

var data = [{
    "subject_name": "PCD",
}, {
    "subject_name": "DAA",
}];

var tpl = Handlebars.compile($("#subjectList").html());
$("#app").html(tpl({
    subjects: data
}));

Example also set up here -
http://jsfiddle.net/K9gLK/

@sachingutte
Copy link
Author

When I change <div id="subjectList" class="hidden"> to <script type="text/x-handlebars" id="subjectList"> it's working. But I still don't understand why it works with template inside <li> and why not with template inside <table> tag.

@doowb
Copy link

doowb commented Dec 20, 2013

@sachingutte see this comment from a previous issue.

@stefanpenner
Copy link
Collaborator

comments in #604 should clarify.

the future HTMLbars project should help mitigate this issue.

@sachingutte
Copy link
Author

@doowb thank you for clarification link. @stefanpenner Indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants