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

No output in table #184

Closed
TLINDEN opened this issue Feb 20, 2012 · 5 comments
Closed

No output in table #184

TLINDEN opened this issue Feb 20, 2012 · 5 comments
Labels

Comments

@TLINDEN
Copy link

TLINDEN commented Feb 20, 2012

Using the following input data:

 {
    "services": [
        {
            "ip": "10.0.0.64",
            "name": "test-sdevel1"
        },
        {
            "ip": "10.0.0.65",
            "name": "test-bdevel8"
        },
        {
            "ip": "10.0.0.64",
            "name": "test-bdevel1"
        }
    ]
}

and the following template:

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>IP</th>
    </tr>
  </thead>
  <tbody>

    {{#each services}}
    <tr>
      <td> {{ this.name }} </td>
      <td> {{ this.ip }}   </td>
    </tr>
    {{/each}}

  </tbody>
</table>

{{#each services}}
 <p class="span-4">Name: {{ this.name }}</p>
 <p class="span-4 last">IP: {{ this.ip }}</p>
{{/each}}

I get:

  <table>
  <thead>
    <tr>
      <th>Name</th>
      <th>IP</th>
    </tr>
  </thead>
  <tbody>

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

  <p class="span-4">Name: test-sdevel1</p>
  <p class="span-4 last">IP: 10.0.0.64</p>

  <p class="span-4">Name: test-bdevel8</p>
  <p class="span-4 last">IP: 10.0.9.65</p>

  <p class="span-4">Name: test-bdevel1</p>
  <p class="span-4 last">IP: 10.0.8.64</p>

As you can see, the second each loop works as expected but the first one doesn't. It doesn't matter if I put the each loop using the table after the other.

I can also put multiple each loops with

tags as in my example in one template, which works well. But it doesn't if I use a table. Since there is one empty column generated in the table, it looks as if handlebars DOES execute the loop but dies for whatever reason after the first loop.

I'm using 1.0.0 Beta 6.

@jasonccp
Copy link

+1

1 similar comment
@walexy
Copy link

walexy commented May 16, 2012

+1

@wagenet
Copy link
Collaborator

wagenet commented May 25, 2012

@TLINDEN Can you make a jsfiddle for this?

@gjcampbell
Copy link

Wrap the handlebars text within the table in comments, like so:

<!--{{#each services}}-->
<tr>
  <td> {{ this.name }} </td>
  <td> {{ this.ip }}   </td>
</tr>
<!--{{/each}}-->

Theory: the browser does not dig text in any part of a table other than in a td/th. The browser moves that text outside of the table. I'll bet that you're not using script tags for your template (I'm not either), and if you did, the browser would ignore what it would otherwise think is out-of-place text.

@wagenet
Copy link
Collaborator

wagenet commented Nov 2, 2012

I've used handlebars in tables without issue. If this is still an issue, please provide a fiddle with 1.0.rc.1.

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

No branches or pull requests

5 participants