Monday, July 12, 2010

Add GET parameter tag

This is custom tag I wrote for myself for solving situations when you have filter form and page numbers in the same page. You want to change ?page=.. or add it if it doesn't exist and save filter form data while moving through pages.

  1. Place this code in your application_dir/templatetags/
  2. Make sure you didn't forget to create in templatetags directory

In template:
{% load add_get_parameter %}

<a href="{% add_get_paramater param1='const_value',param2=variable_in_context %}">
    Link with modified params

It's required that you have 'django.core.context_processors.request' in TEMPLATE_CONTEXT_PROCESSORS or request in context.

Complete code in dangosnippets:

1 comment: