Django Template Save operation result into a variable -
i have listing counter "2370" , page shows "12" item want calculate pages number, did solution below
{% widthratio listing.total_count 12 1 %}
so, how can save result variable?
{% set total_pages = widthratio listing.total_count 12 1 %}
this 1 didn't work
if choose rohans comment, if write own templatetags, use assignment_tag
(https://docs.djangoproject.com/en/1.7/howto/custom-template-tags/#assignment-tags, exists since django 1.4).
@register.assignment_tag def page_numbers(total_items, items_per_page): if not total_items: return 0 # int divisions round down (1 / 12 = 0), add 1 cover return total_items / items_per_page + 1
within template should use;
{% page_numbers listing.total_count 12 page_nrs %}
Comments
Post a Comment