Reputation: 529
I have a multiple tag filter system on my website, i.e. I can click a tag to filter by "foo", then click on another tag to filter by "bar" as well. When I click the tag, it appends a parameter to the url, as such:
Then, the current tags used to filter are displayed at the top of the page. I need to be able to click a tag, and remove its associated parameter from the url. If I clicked "bar" tag at the url given by "b", I would expect the url "a". How can I manipulate the URL as such?
Currently, if you click a tag, it removes ALL tags from the filter (just a simple redirect back to the main domain), because I haven't been able to find a better way to play with the url.
EDIT: Add tag
{% for tag in value.tags %}
{% if tag.name %}
<a href="{{ request.get_full_path }}?tag={{ tag.name.strip }}">
{{ tag.name }}
</a>
{% endif %}
{% endfor %}
Remove
{% for tag in tag_filters %}
<a href='/'>
{{ tag }}
</a>
{% endfor %}
Upvotes: 1
Views: 643
Reputation: 41950
Something like this ought to work...
{% for tag in tag_filters %}
{% with "/?tag="|add:tag as to_cut %}
<a href='{{ request.get_full_path|cut:to_cut }}'>
{% endwith %}
{{ tag }}
</a>
{% endfor %}
...although this might be better solved with a single query parameter which can take multiple strings, like...
http://www.domain.com/?tags=foo+bar+baz
...and using JavaScript to manipulate the URL, since it's much more flexible.
Upvotes: 1