Language Code

To dynamically set the language of your template, change the html-tag:

<!DOCTYPE html>
<html lang="en">
...

To:

<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}">

Meta Description

To easily add specific meta descriptions for each django CMS page, simply add the appropriate tag to the template.

...
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
...

Simply add the {% page_attribute 'meta_description' %} tag:

...
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="{% page_attribute 'meta_description' %}">
    <meta name="author" content="">
...

Page Title

Next, we want to setup a dynamic page title. Navigate to the <title></title> tag and check its content. It currently reads: “Clean Blog - About.” 

    <meta name="author" content="">

    <title>Clean Blog - About</title>

    <!-- Bootstrap Core CSS -->
    ...

Replace this with:

<meta name="author" content="">

    <title>
        {% block title %}
            {% page_attribute "page_title" %} - {{ request.site.name }}
        {% endblock title %}
    </title>
    <!-- Bootstrap Core CSS -->
    ...

The block title might be used by third party addons, as well as provide additional information on your page. 

In this case, we want to display the page_title attribute which might read “Home” or “Blog”. The second param request.site.name will display “Site” or whatever you configured in the Sites section earlier on.

Logo

The logo is currently defined as follows:

<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
    ...
    <a class="navbar-brand" href="index.html">Start Bootstrap</a>
</div>

To make it more dynamic, let’s change the href-attribute to “/" and "Start Bootstrap" to: 

<a class="navbar-brand" href="/">{{ request.site.name }}</a>

Footer

Let’s conclude the first step of the implementation here by adding dynamic information to the footer. 

It currently reads: 

<p class="copyright text-muted">Copyright &copy; Your Website 2014</p>

We can make “Your Website” dynamic by using:

{{ request.site.name }}

Django offers a wide range of template tags you can use, which you can find here

One of these is {% now "Y" %}, which will render the current year. The end result might look something like this:

<p class="copyright text-muted">Copyright &copy; {{ request.site.name }} {% now "Y" %}</p>

Cleanup

Divio Cloud installs all static files and templates from addons directly into your project. Any subsequent addon update will not override these templates. We recommend that you remove at least the following folders:

  • static/aldryn_bootstrap3
  • static/djangocms_text_ckeditor
  • static/djangocms_googlemap
  • templates/admin
  • templates/aldryn_bootstrap3
  • templates/cms/
  • templates/djangocms_file, _googlemap, _link, _picture, _snippet, _video, _style

This will not break your project, the templates will just fallback to the addons default templates following the Django template inheritance.

django CMS has very few strict conventions on how to use or name things in your template. This is merely a best practice example to help you get started. Feel free to adapt it to your own personal flavour.

Did this answer your question?