Navigation Nodes in django-cms example - django

Can you give me an example how can i use Navigation Nodes?
Cannot find examples in documentation.
There is this {{ node }} but where is it coming from?
Particalarly i am intereisted in {{ node.is_leaf_node }}.

Each navigation node is simply a link/entry in your menu tree so they are generated from your page layout, for example:
- Home
- About
- Projects
- Project A
- Project B
- Contact
creates a menu with each page representing a node in the menu tree.
There's an example of them working in the default menu.html template (where child is a node in the menu):
{% load menu_tags %}
{% for child in children %}
<li class="{% if child.selected %}selected{% endif %}{% if child.ancestor %}ancestor{% endif %}{% if child.sibling %}sibling{% endif %}{% if child.descendant %}descendant{% endif %}">
{{ child.get_menu_title }}
{% if child.children %}
<ul>
{% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
</ul>
{% endif %}
</li>
{% endfor %}

Related

Make menu item not clickable in Django CMS

I have a Django application running using Django CMS.
I am trying to make one specific submenu not clickable.
The menu is like this:
item1|item2|item3
sub_item3
sub_item3
What I want is that everything is clickable except for "item3" menu item.
How can I achieve this knowing item3 is a Django CMS page itself as are each of its children pages?
The idea behind this is to prevent that the user sees an empty page when he clicks on the top "item3" menuitem.
Here is how I have done this to keep it from linking anywhere:
{% load cms_tags menu_tags %}
{% for child in children %}
<li>
{% if child.is_leaf_node %}{{ child.get_menu_title }}{% else %}{{ child.get_menu_title }}{% endif %}
{% if child.children %}
<ul>
{% show_menu 0 100 100 100 "menu/top-menu.html" "" "" child %}
</ul>
{% endif %}
</li>
{% endfor %}
In your case you may want a class with some css like this from Disable a link using css
.active {
pointer-events: none;
cursor: default;
}
Ok I fixed it with a mix of the previous answer and these links https://groups.google.com/forum/?fromgroups=#!topic/django-cms/aS2Ew2mf8XY and the docs https://django-cms.readthedocs.org/en/2.4.0/extending_cms/app_integration.html#how-it-works (navigation modifiers).
from menus.base import Modifier
from menus.menu_pool import menu_pool
class MyMode(Modifier):
"""
"""
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
if post_cut:
return nodes
for node in nodes:
if node.title == u'Page not clickable':
node.no_click = True
return nodes
menu_pool.register_modifier(MyMode)
With this template
% load cms_tags menu_tags %}
{% for child in children %}
<li>
{% if not child.no_click %}{{ child.get_menu_title }}{% else %}{{ child.get_menu_title }}{% endif %}
{% if child.children %}
<ul>
{% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
</ul>
{% endif %}
</li>
{% endfor %}
And in my main template (base.html) I add the menu with
{% show_menu 0 100 100 100 "menu.html" %}

How to add a class to a menu item that has children (nested pages) in Django-CMS

I'm working on a project where there's some specific styling on a menu item which has nested children. The menu structure looks something like this
Home
|
About
|
Services
|_ web design
|_ social marketing
|_ traditional marketing
I'm using {% show_menu 0 100 100 100 "menu.html" %} in my template and I have the following inside my menu.html:
{% load menu_tags %}
{% for child in children %}
<li class="{% if child.selected %}active{% endif %}{% if child.sibling %}dropdown{% endif %}">
{{ child.get_menu_title }}
{% if child.children %}
<ul>
{% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
</ul>
{% endif %}
</li>
{% endfor %}
I put {% if child.sibling %}dropdown{% endif %} in there to illustrate where I want the class to be added, but targeting it as a child.sibling is not the right way of doing it. Is there a way to target the specific dropdown like this {% if child.has_children %}dropdown{% endif %}?
Thanks
{% if child.children %}...{% endif %}

django-cms menu disappeared

I am using django-cms 2.2 and my menu suddenly disappeared. There's no error message. Page renders normally, with exception of menu. I am using:
{% show_menu 0 0 100 100 "menu/show_menu_template.html" %}
command, and as i checked it goes inside of show_menu_template.
showmenu_template is standard and as follows, it was working before, cheers
{% load menu_tags %}
{% for child in children %}
<li class="{% if forloop.last %}last {% endif %}{% if child.selected %}current selected{% endif %}{% if child.ancestor %}ancestor{% endif %}{% if child.sibling %}sibling{% endif %}{% if child.descendant %}descendant{% endif %}">
{{ child.get_menu_title }}
{% if child.children %}
<ul>
{% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
</ul>
{% endif %}
</li>
{% endfor %}
I've changed the tag inside the template and it started working, am not sure why it was not working before and stopped as such but what to do
{% show_menu 1 1 100 100 "menu/show_menu_template.html" %}

show children nodes depending on selected parent

Hi i've been looking all over and can't find the answer to this. I have only 3 months experience in using python/django so excuse my dummy quesion!
Im using django mptt to display a simple nested set navigation.
<ul class="root">
{% recursetree nodes %}
<li>
{{ node.name }}
{% if not node.is_leaf_node %}
<ul class="children">
{{ children }}
</ul>
{% endif %}
</li>
{% endrecursetree %}
this works fine - however i would like to show only children of the selected category (based on slug) and not all of them.
Any ideas ???
i finally did it like this:
{% recursetree nodes %}
<li>
<a href='/{{ node.get_absolute_url}}'>{{ node.name }}</a>
</li>
{% if not node.is_leaf.node %}
{% for c in child %}
{% if c in node.get_children %}
{% if forloop.first %}
<ul class="children">
{{ children }}
</ul>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endrecursetree %}
in views
category = get_object_or_404(Category, slug=slug)
child = category.get_children()
if not child :
child = category.get_siblings()
but it is a hack. has anyone got better idea?
You need to send down some information about what node you're in, and then it's a simple if statement.
Regarding how to send down the node information universally, there are a couple ways to do this in Django, and none of them are perfect. My preferred method is context processors: http://docs.djangoproject.com/en/1.3/ref/templates/api/#writing-your-own-context-processors
{% recursetree nodes %}
<li>
{{ node.name }}
{% if node.name == category.name %}
<ul>
{{ children }}
</ul>
{% endif %}
<li>
{% endrecursetree %}
You can try this:
{% recursetree nodes %}
#check if the node is a child node
{% if node.is_child_node %}
<a href="{{ node.get_absolute_url }}" >{{ node.name }}</a>
{% endif %}
#check if a root node is the current category
{% if node.is_root_node and node.name == category.name %}
{{ children }}
{% endif %}
{% endrecursetree %}

How do you access the menu model from a Zotonic template?

I want to write my own style of menu, but I would prefer to do it in the templates rather than making my own menu scomp.
I basically want to be able to do something like:
{% if m.menu %}
<ul>
{% for top_level_id in m.menu %}
{% with m.rsc[top_level_id] as top_level %}
<li>{{ top_level.title }}
{% if top_level.menu %}
<ul>
{% for mid_level_id in top_level.menu %}
{% with m.rsc[mid_level_id] as mid_level %}
<li>{{ mid_level.title }}</li>
{% endwith %}
{% endfor %}
</ul>
{% endif %}
</li>
{% endwith %}
{% endfor %}
</ul>
{% endif %}
How do you access the menu model from a Zotonic template?
To add to my previous answer. The standard _menu.tpl receives a list with all menu items. This list is the result of a depth-first tree walk of the complete menu. Every menu is a record with
{MenuRscId, DepthOfMenu, NrInSubMenu, HasSubMenuFlag}
Where the top level menu has a depth of 1 and the first menu item in a menu has a nr of 1.
All menu items that the current user is not allowed to see are filtered out.
The code of the default template:
<ul id="{{ id_prefix }}navigation" class="clearfix at-menu do_superfish">
{% for mid,depth,nr,has_sub in menu %}
{% if not mid %}{% if depth > 1 %}</ul></li>{% endif %}
{% else %}
{% if nr == 1 and not forloop.first %}<ul{% if mid|member:path %} class="onpath"{% endif %}>{% endif %}
<li id="{{ id_prefix }}nav-item-{{nr}}"
class="{% if is_first %}first {% endif %}{% if is_last %}last{% endif %}">
<a href="{{ m.rsc[mid].page_url }}"
class="{{ m.rsc[mid].name }}{% if mid == id %} current{% else %}{% if mid|member:path %} onpath{% endif %}{% endif %}">{{ m.rsc[mid].short_title|default:m.rsc[mid].title }}</a>
{% if not has_sub %}</li>{% endif %}
{% endif %}
{% endfor %}
{% if forloop.last %}{% include "_menu_extra.tpl" %}{% endif %}
</ul>
The (upcoming) 0.5-release and tip of Zotonic use a template to display the menu. Check mod_menu/templates/_menu.tpl.
This template is called by the menu scomp.