Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default model additions for expanding menus #4

Open
alastc opened this issue Nov 27, 2010 · 0 comments
Open

Default model additions for expanding menus #4

alastc opened this issue Nov 27, 2010 · 0 comments

Comments

@alastc
Copy link

alastc commented Nov 27, 2010

Hi,

I was trying to get treemenus to create an expanding menu effect, where the children of the current page get expanded, but not other sections. (e.g. http://ukwindsurfing.com/information/regions/). NB: I'm not a programmer as such, so I may have missed a point or two.

I've got it working, as it's a similar problem to highlighting the current page. However, it's much easier with a couple of additions to the menu item model:

def this_section(self):
    url_part = self.url
    list_of_sections = url_part.split("/")
    section = list_of_sections[-2]
    return section

def matching_url(self):
    return "^" + self.url + "$"

Combined with the code from 'Automatically select menu items' section you can use this in the templates:

{% load tree_menu_tags %}
{% if menu_item.has_children %}
<li>{% if menu_item.matching_url|match_path:request.path %}<strong class="nolink">{{ menu_item.caption }}</strong>{% else %}
    <a href="{{ menu_item.url }}">{{ menu_item.caption }}</a>{% endif %}
    {% if menu_item.this_section in request.path %}
    <ul>
        {% for child in menu_item.children %}
            {% show_menu_item child %}
        {% endfor %}
    </ul>{% endif %}
</li>{% else %}
<li>{% if menu_item.matching_url|match_path:request.path %}<strong class="nolink">{{ menu_item.caption }}</strong>{% else %}
<a href="{{ menu_item.url }}">{{ menu_item.caption }} </a>{% endif %}</li>{% endif %}

I know you've outlined extension methods, but as someone with limited programming experience,
it seems a lot simpler to make a couple of additions to the model (and the match_path addition to the template tags).

Could those be included by default?

I've created a patch if that helps, which is my first foray into Git.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant