views:

379

answers:

1

Hi,

I need to make a links section for a django project that show only the non active links, ie. if i'm at home, the section only shows the about link and not the home link.

Im using something like this in my template:

{% ifequal item.url request.path %}
<a href = "{{item.url}}" > {{item.name}} </a>
{% endifequal %}

it works fine but, if for example I visit "/section/page/" the "section" link still showing and i don't want to this happen.

it was wordering if i can use something like:

{% ifequal item.url+* request.path %}

any body can give me a clue to solve this problem?

thanks in advance

A: 

I believe this website has the information you need. Basically you create a custom template tag that allows you to use a regexp to match the url to the active link, just like you would with your urls.

You might have to modify it slightly to get the exact functionality you want, but this should give you a good start.

Alex Jillard
it was an start point. Finally I wrote a very short function that do the trick:@register.simple_tagdef active(request, pattern, name): import re if not re.search(pattern, request.path): return '<a href="%s">%s</a>' %(pattern,name) return ''
z3a
obviously indented :P
z3a