olalonde / handlebars-paginate

Pagination helper for Handlebars.
http://syskall.com/pagination-with-handlebars/
59 stars 21 forks source link

add options id #15

Closed PhilippeHidayat closed 8 years ago

PhilippeHidayat commented 8 years ago

adding options "id" in-case the is link that use id in the pagination link

jimf commented 8 years ago

I'm not sure this really belongs in the helper, given that id isn't changing anywhere and isn't really tied to any of the pagination logic. I'd recommend instead providing it with the rest of your template data and referencing it directly. For example:

var html = template({
  id: myId,
  pagination: {
    page: 3,
    pageCount: 10
  }
});
{{#paginate pagination type="last"}}
  <li id={{../id}}{{#if disabled}} class="disabled"{{/if}}><a href="?p={{n}}">Last</a></li>
{{/paginate}}

Let me know if I'm missing something.

PhilippeHidayat commented 8 years ago

I did tried referencing that "id" directly, but handlebars can't read it when it is placed between {{#paginate ...}} and {{/paginate}}. No idea why. Thats why i tried to pass it through the helper.

jimf commented 8 years ago

Ah, yes, that's the way Handlebars deals with scoping. When inside the paginate block expression, the context changes. Note in my example that I'm using ../id. That instructs the engine to use id in the scope above. See the "Handlebars Paths" section of the official docs for more.

jimf commented 8 years ago

Closing due to inactivity. Feel free to reopen.