I'm new to django and django-cms. I read the official docs and tried to find any other info on the internet, that could guide me through making dropdown menus in django cms. But unfortunately for me, the official docs are really raw (I don't get it at all what's about the menus) and on the internet there's nothing sensible enough.
Please explain me or give a step by step guide on this topic.
At this moment the menu is working and the only code that I have for that is a pair of <ul> and this {% show_menu 0 100 100 100 %} inside them.
The most simple way to get dropdowns working in django-cms is to follow this:
(In this example I am using Bootstrap code for my menu)
In your base.html file (or any other name that you are using) use this way of showing your menu {% show_menu 0 10 10 10 %}
As an example, this is what i used in my code in base.html to render the menu:
<ul>
{% show_menu 0 10 10 10 "menu/custom-menu.html" %}
</ul>
Now create the template in the directory "/templates/menu/custom-menu.html" with these sekizai tags and similar html code that will overwrite your base.html and render your menu with drop-down elements:
<div class="dropdown">
{% for child in children %}
<!-- no child pages -->
{% if child.is_leaf_node %}
<li>{{child.get_menu_title }}</li>
{% endif %}
<!-- /no child pages -->
<!-- has child pages -->
{% if not child.is_leaf_node or child.ancestor %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{{child.get_menu_title }}<b class="caret"></b></a>
<ul class="dropdown-menu">
{% if child.get_descendants %}
{% for kid in child.get_descendants %}
<li>
<a href="{{ kid.get_absolute_url }}">
{{kid.get_menu_title }}
</a>
</li>
{% endfor %}
{% endif %}
</ul>
</li>
{% endif %}
<!-- /has child pages -->
{% endfor %}
<!-- /end for child -->
</div>
And dont forget to put the {% load menu_tags %} sekizai tag in the top of your custom-menu.html file.
Related
while the 'unread_list' API works, I cannot get the tag {% live_notify_list list_class="dropdown-menu" %} to work.
The tag definition is:
def live_notify_list(list_class='live_notify_list'):
html = "<ul class='{list_class}'></ul>".format(list_class=list_class)
return format_html(html)
correct me if I am wrong, but this doesn't do anything but returning an unsorted list. I would like to display all the notifications. According to the documentation (documentation) all I need to do is to use {% live_notify_list %} however, this doesn't display anything.
The library I am using at github.
DevKing, hopefully you have solved the issue. To give more context, the {% live_notify_list %} is used for getting real-time updates of notifications that can be used in a dropdown on a navbar. A user can click and get a dropdown of the most recent notifications (the default is 5). If you want a list of all notifications, you can provide a link to {% url 'notifications:unread' %}.
You will need to include this
{% load notifications_tags %}
<script src="{% static 'notifications/notify.js' %}" type="text/javascript"></script>
{% register_notify_callbacks callbacks='fill_notification_list,fill_notification_badge' %}
And then you can place this within your navbar
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Notifications {% live_notify_badge %}
<span class="glyphicon glyphicon-user pull-right">
</span>
</a>
<ul class="dropdown-menu" id="notice-link">
<a href="{% url 'notifications:unread' %}">
{% live_notify_list %}
</a>
</ul>
</li>
The {% live_notify_badge %} will show you the number of unread notifications while the {% live_notify_list %} will provide the list of recent notifications. The js added above will pull new notifications every 15 seconds (which you can make shorter/longer).
I want to create a Menu that handles information about the current page and their siblings for example, if I have the following tree:
If I am in page Child 1 my menu should only display Page 1 and the children 1-3
This can be achieved with the following code:
{{ page.parent.title }}
<ul>
{% page_menu page.parent %}
</ul>
The problem I have is that I would like to display the Grand Child 1 and 2 if I am located in Child 2. How can I do that?
I tried the following:
<ul>
{% for page in branch_page %}
{% if page.is_current_sibling %}
<li> {{ page.title }}
{% if page.is_current_or_ascendant %}
{% page_menu page %}
{% endif %}
{% endif %}
{% endfor %}
</ul>
But it doesn't work and it does not display any error, how can I do this in another way?
The page_menu template tag lets you pass in an optional parent page, and a menu template that will be used recursively for rendering children, eg where "page" is the current page:
{% load pages_tags %}
{% page_menu page "pages/menus/tree.html" %}
ref: https://groups.google.com/forum/#!msg/mezzanine-users/Fk2Nm6K6qho/VyePF5D6CXgJ
I'm making a site for which I use cmsplugin-articles 0.2.2. That means that there's a page on the site (News) which has nested child pages which are the news. In the parent page you view a list of news teasers. (This is the way the plugin works.)
Looking into the template of the article teaser that the plugin provides:
{% load article_tags i18n %}
<div class="article">
{% block teaser_head %}
<time datetime="{{ article|published_at|date:"Y-m-d" }}">{{ article|published_at|date:"d.m.Y" }}</time>
<h2>{{ article|teaser_title }}</h2>
{% endblock %}
{% block teaser_body %}
{% with article|teaser_image as image %}
{% if image %}
<img src="{{ image.url }}" />
{% endif %}
{% endwith %}
<p>
{% teaser_text article %}
{% trans "More" %}
</p>
{% endblock %}
</div>
you can see the templatetag {% teaser_text article %} that should show some kind of text in the news teaser when rendering the News page.
I've published some news with some text for each one and when I go to the News page I can see the teasers list ok, but not any text, only the title, date, paginator and the "more" link, that proceed from other templatetags different than {% teaser_text %}.
Now the question is: does anybody knows how I can show each news text into each teaser (better an extract) when rendering the News page?
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" %}
I'm looking to customise the sub_menu.html template with DjangoCMS, and have currently got the following code for the menu:
{% if children %}
<div class="unit subnav">
<h3>{% page_attribute "menu_title" %}</h3>
<ul>
{% for child in children %}
<li class="{% if child.selected %}on{% endif %}{% if child.ancestor %}ancestor{% endif %}{% if child.sibling %}sibling{% endif %}{% if child.descendant %}descendant{% endif %}">
{{ child.get_menu_title }}
</li>
{% endfor %}
</ul>
</div>
{% endif %}
So basically, this detects if the page has children, and then adds the sub navigation if children of this page exist.
So far, so good.
My problem is that when I navigate to the child pages themselves - the menu disappears, so I'd like to detect if the page is a "child" below level 1. This should stop all pages having a nav (because they're all children of the homepage I presume) but should allow those below the main level of navigation to have the menu appear.
If anybody can lend a hand or point me in the right direction, that would be brilliant.
OK, it might not make sense to people, but I was able to get to the bottom of this with the following if statement within my subnav template...
{% if children or request.current_page.level > 0 %} subnav in here {% endif %}