How to place breadcrumb under Bootstrap3 jumbotron in Django CMS? - django

How to place breadcrumb under jumbotron? In base.html there is {% block content %} where jumbotron is being called. But if I add inside there
{% block breadcrumb %}
{% show_breadcrumb 0 "cms/breadcrumb.html" 0 %}
{% endblock %}
then nothing shows.
I've tried to insert that in feature.html page like this:
...
{% block content %}
<div class="jumbotron>
{% placeholder "feature" %}
</div>
<div class="breadcrumb">
{% block breadcrumb %}
{% endblock %}
</div>
<div>
{% placeholder "content" %}
</div>
{% endblock %}
But this magic don't shows breadcrumbs :-(
UPD: only thing that is shown is an empty row under jumbotron (in case if I add breadcrumb in feature.html as wrote above).

Its should be:
{% show_breadcrumb 0 "menu/breadcrumb.html" 0 %}
i.e show_breadcrumb with an underscore.
Docs: http://django-cms.readthedocs.org/en/latest/reference/navigation.html#show-breadcrumb

Holy crap, I made it!
I just added {% load cms_tags staticfiles sekizai_tags menu_tags thumbnail %} at the beggining of feature.html and changed a little bit code:
<div class="breadcrumb">
{% block breadcrumb %}
{% show_breadcrumb 0 "cms/breadcrumb.html" 0 %}
{% endblock %}
</div>
Now breadcrumbs shown under jumbotron with slider. Nice!

Related

{% block something %} always being displayed despite being False in an if-statement

I have two types of blog articles. Regular blog articles, and translation articles. They both have different html markup. I have a boolean variable translation_bool in my models to check if it is a translation article or not. If it is I want it to display my {% block translation %} and if not {% block translation %}. It worked with plain html code and not using html tags. But I had so much reusable code that it got troublesome to manage.
So my question is: why is this happening despite it being inside of an if statement.
Article template:
{% extends "base_generic.html" %}
{% load static %}
{% block js %}...{% endblock %}
{% if blogpost.translation_bool == True %}
{% block translation %}....{% endblock %}
{% else %}
{% block content %}...{% endblock %}
{% endif %}
{% block sidebar %}....{% endblock %}
In Base Generic Template:
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-8">
{% block content %}{% endblock %}
{% block translation %}{% endblock %}
</div>
<div class="col-md-3">
{% block social_media %}...{% endblock %}
{% block sidebar %}...{% endblock %}
</div>
</div>
</body>
This is because blocks not defined in child template will render value from parent template. So in your case you should perform validation inside parent template. Or if it's impossible override blocks in child with empty content:
{% block translation %}
{% if blogpost.translation_bool == True %}
{{ block.super }}
{% else %}
{% endif %}
{% endblock %}
{% block content %}
{% if blogpost.translation_bool == False %}
{{ block.super }}
{% else %}
{% endif %}
{% endblock %}
Note {{ block.super }} will render content from parent template.

Expanding a template in an other templates' block

I have to do a little websites rendering a few pages with static content.
The pages are based on a base.html template, this template has a content block.
The pages may have (or not) an aside element (always the same aside).
Thus far I can do something like this :
page.html :
{% extends "base.html" %}
{% block content %}
{% include "page-content.html" %}
{% endblock %}
page-content.html :
{% extends "content-with[out]-aside.html" %}
{% block content %}
foo
{% endblock %}
content-with-aside.html :
<div>
<div>
{% block content %}
{% endblock %}
</div>
<aside>
aside
<aside>
</div>
content-without-aside.html :
<div>
<div>
{% block content %}
{% endblock %}
</div>
</div>
But that supposes using a template with no usefulness but defining if the page has or not the aside.
I could also define a base-with-aside.html and a base-without-aside.html templates. But could I do something like this?
page.html :
{% extends "base.html" %}
{% block content %}
{% expandblock "content-with[out]-aside.html" %}
{% block content %}
foo
{% endblock %}
{% endexpandblock %}
{% endblock %}
In Jinja perhaps?
At worst case I could define a custom template tag, but I would like to know it there already is a feature like this.

Using content blocks in Django Template

I am having an issue when trying to make a generic template that is then extended into a child template.
Post.html
{% extends "blog\blog_base.html" %}
{% block title %} The Blog {% endblock %}
{% block menu %}
{% endblock %}
<h1>The Blogs Index Page</h1>
{% block content %}
<h2> Posts </h2>
{% for post in latest_post_list %}
<h3> {{ post.title }} </h3>
<p> {{ post.body|linebreaks }} </p>
{% endfor %}
{% endblock %}
blog_base.html
<body>
{% block menu %}
{% for menu in menu %}
{{ menu.page_name }}
{% endfor %}
{% endblock %}
<div class = "content">
{% block content %} <p> Place Holder </p> {% endblock %}
</div>
</body>
The block for the content works.
The block for the menu does not, it displays no page_name property of the menu object.
But if i insert ->
{% for menu in menu %}
{{ menu.page_name }}
{% endfor %}
straight into the Post.html template, it works. Oh it also automatically makes the menu a list as well which confuses me. Why does it make a list with bullet-points and not just print out each menu object on its own line?
By including the block tags in Post.html, you're overriding the menu in the base template. Remove the following from the post template:
{% block menu %}
{% endblock %}

Djangocms template not showing up

I have a basic DjangoCMS up and running.
base.html contains:
{% block content %}{% endblock content %}
I also have feature.html:
{% extends "base.html" %}
{% load cms_tags %}
{% block title %}{% page_attribute "page_title" %}{% endblock title %}
{% block content %}
<div>
{% placeholder "feature2" %}
</div>
<div class="jumbotron"">
{% placeholder "feature" %}
</div>
<div>
{% placeholder "content" %}
</div>
{% endblock content %}
I added the "feature2" placeholder in the above, and it correctly displays for editing on the site.
I then added a new line to base.html:
{% block base_logo %}{% endblock base_logo %}
and created a new file, base_logo.html:
{% extends "base.html" %}
{% load cms_tags %}
{% block base_logo %}
<div>
{% placeholder logo %}
</div>
{% endblock base_logo %}
I expected this to also appear on the site for editing, but it doesnt. I have added the base_logo.html to the CMS_TEMPLATES in settings.py and TEMPLATE_DIR is also pointing correctly.
What else do I need to do for Djangocms to pick up my new template?
Take a look at template inheritance.
You're trying to use two {% extends %} tags, which won't work. You should use the {% include %} tag for base_logo, because it seems you'd want to include this in many templates. This question provides more info.

Issue trying to customizing the admin in Django

In order to add some links in the admin of my site I added a custom block (surrounded in red in the images below) to admin/base.html and set it in admin/base_site.html.
The issue is that it's shown in all admin pages (eg connexion screenshot shown below), while I'd like to show it only in the site admin first page.
Anybody could help?
admin/base.html
...
<!-- Content -->
<div id="content" class="{% block coltype %}colM{% endblock %}">
{% block pretitle %}{% endblock %}
{% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}{% endblock %}
{% block content %}
{% block object-tools %}{% endblock %}
{{ content }}
{% endblock %}
{% block sidebar %}{% endblock %}
{% block myblock %}{% endblock %} <!-- custom block -->
<br class="clear" />
</div>
<!-- END Content -->
....
admin/base_site.html
....
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %}
{% block branding %}
<h1 id="site-name">{% trans 'Administration de Django' %}</h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{% block myblock %}
<div style="margin-top:160px;">
<div style="font-size:18px; color:#666666;font-weight:bold;margin-bottom:10px;">Rapports</div>
Rapports journaliers<br/>
Rapports mensuels
</div>
{% endblock %}
....
Site admin
Connexion
Then you are better off overriding admin/index.html
For this purpose I would like to recommend to you django-admin-tools application. As documentation says:
django-admin-tools is a collection of extensions/tools for the default
django administration interface, it includes:
a full featured and customizable dashboard;
a customizable menu bar;
tools to make admin theming easier.
Please join the mailing list if you want to discuss of the future of django-admin-tools.