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

Any template tag to show parent menu title as sub menu title #135

Closed
sunjoomoon opened this issue Feb 9, 2016 · 10 comments
Closed

Any template tag to show parent menu title as sub menu title #135

sunjoomoon opened this issue Feb 9, 2016 · 10 comments

Comments

@sunjoomoon
Copy link

In the side bar to show sub menu title, is there such template tag? Ex, Product > Software > Mobile and I am in Mobile page, then sub menu title is the root of selected menu which n this case is Product.

@batiste
Copy link
Owner

batiste commented Feb 11, 2016

It is a bit hard to understand what you mean but I think this should satisfy your needs:

http://django-page-cms.readthedocs.org/en/latest/navigation-template-tags.html#pages-dynamic-tree-menu

@batiste
Copy link
Owner

batiste commented Feb 11, 2016

Here is the template that you can replicate within your project to fit your needs. Tell me if this template tag didn't fit your needs somehow: https://github.com/batiste/django-page-cms/blob/master/pages/templates/pages/dynamic_tree_menu.html

@sunjoomoon
Copy link
Author

Thanks for the notes, I tried all available in the document but not being able to achieve my needs.

For example, from below page menus and I am in the Mobile page, then I wish to show the top most page title. In this case Product is the top most page, so a template to show product.title. So this can be shown in all the pages under Product pages.

Product
- Software 
- - Mobile

@batiste
Copy link
Owner

batiste commented Feb 14, 2016

If I understand your you have this tree::

Product
- Software 
- - Mobile

And you want to only display:

Product

?

@sunjoomoon
Copy link
Author

Yes. For all the pages under Product, the 5ah to show Product. Same as page title which differs for every page but sidemenu title always shows the top most menu title for all the pages under Product page. Hope this clears up the confusion.

@batiste
Copy link
Owner

batiste commented Feb 15, 2016

Edited: wrong example

Well Django Page CMS uses Django MPTT to represent trees. You can use get_root to get the root page ("the product page"): http://django-mptt.github.io/django-mptt/mptt.models.html#mptt.models.MPTTModel.get_root

So I guess things would look a bit like this

{{ current_page.get_root.title }}

Or use pages_navigation which contains all the root pages

{% for page in pages_navigation %}
     {% if page == current_page.get_root %}
          Do something specific with the root page
     {% endif %}
{% endfor %}

@sunjoomoon
Copy link
Author

Hmm, did not think of that before hand, let me give it a try. Your advice makes good sense. Thanks.

@sunjoomoon
Copy link
Author

Trying things out as per your advice, here is what I did. I put tags in the head of the template

{% load cache pages_tags ckeditor_placeholder mptt_tags %}

And put the code like below (perhaps something is missing here, I am afraid)

<h3 class="widget-title"> {% current_page.get_root().title() %} </h3>

Then below returned, what am I missing?

Invalid block tag: 'current_page.get_root().title()', expected 'endblock'

Traceback detail shows

/../pages/views.py in __call__
                answer = self.delegate(request, context, delegation, **kwargs)
                if answer:
                    return answer
            if kwargs.get('only_context', False):
                return context
            template_name = kwargs.get('template_name', template_name)
                        return render(request, template_name, context)  ...

        def resolve_page(self, request, context, is_staff):
            """Return the appropriate page according to the path."""
            path = context['path']
            lang = context['lang']
            page = Page.objects.from_path(path, lang,

@sunjoomoon sunjoomoon reopened this Mar 24, 2016
@batiste
Copy link
Owner

batiste commented Mar 25, 2016

You don't put parenthesis in the django template language (I know this is weird sometimes). Also you need {{ }} for an expression ({% %} is for template tags) so that will that:

{{ current_page.get_root.title }}

Or better yet, using the show_content template tag (this one handle translation depending of the user language):

{% show_content current_page.get_root title %}

@sunjoomoon
Copy link
Author

Many thanks. Yes, they worked well - just a little typo got me stranded for a minute though.

This worked well
{{ current_page.get_root.title }}

Below first showed none
{% show_content current_page.get_root title %}

So I had a look around existing templatetags, and found out a typo - missed string " ". And below worked well.
{% show_content current_page.get_root "title" %}

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

2 participants