ExpressionEngine pagination + Stash + CartThrob


/ Published in: HTML
Save to your folder(s)

A nice DRY way of using Stash for EE pagination


Copy this code and paste it in your HTML
  1. {!-- template URL: /products/category/{category_name} --}
  2.  
  3. {!-- ============================================
  4. store item rows, pagination & item-count data for use later
  5. ================================================== --}
  6. {exp:stash:set parse_tags="yes" parse_conditionals="yes"}
  7. {stash:results_rows}
  8. {exp:channel:entries channel="products" disable="categories|member_data" limit="10" paginate="both"}
  9. {paginate}{stash:pagination}<p>Page {current_page} of {total_pages} pages {pagination_links}</p>{/stash:pagination}{/paginate}
  10. {stash:all_items}{absolute_results}{/stash:all_items}
  11. {if count == 1}{stash:first_item}{absolute_count}{/stash:first_item}{/if}
  12. {if count == total_results}{stash:last_item}{absolute_count}{/stash:last_item}{/if}
  13.  
  14. {!-- build up the result rows ========================= --}
  15. <tr>
  16. <td>{product_sku}<input type="hidden" name="entry_id[{count}]" value="{entry_id}" /></td>
  17. <td>{title}</td>
  18. <td>{if product_price}{product_price}{if:else}TBC{/if}</td>
  19. <td>
  20. <label for="quantity">Quantity</label>
  21. <input id="quantity" type="text" name="quantity[{count}]" />
  22. </td>
  23. </tr>
  24. {/exp:channel:entries}
  25. {/stash:results_rows}
  26. {/exp:stash:set}
  27.  
  28. {!-- ============================================
  29. build up the final 'content' variable using data
  30. stored above, ready for output by the View template
  31. ================================================== --}
  32.  
  33. {exp:stash:set name="content"}
  34. {exp:channel:category_heading channel="products"}
  35. <h1>{category_name}</h1>
  36. {if category_description}<p>{category_description}</p>{/if}
  37. {/exp:channel:category_heading}
  38.  
  39. {exp:stash:get name="pagination"}
  40. <p><em>Displaying items {exp:stash:get name="first_item"} to {exp:stash:get name="last_item"} of {exp:stash:get name="all_items"}</em></p>
  41.  
  42. {exp:cartthrob:multi_add_to_cart_form return="..."}
  43. <table id="product-list">
  44. <tr>
  45. <th>Code</th>
  46. <th>Name</th>
  47. <th>Price</th>
  48. <th>Quantity</th>
  49. </tr>
  50. {exp:stash:get name="results_rows"}
  51. </table>
  52. <input type="submit" value="Add all to order form" />
  53. {/exp:cartthrob:multi_add_to_cart_form}
  54.  
  55. {exp:stash:get name="pagination"}
  56. {/exp:stash:set}
  57.  
  58. {embed='site/view'}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.