Using templates — django-vintage v0.1 documentation

django-vintage v0.1 documentation

# Using templates

- Table of Contents
- index
  next
  previous

# Using templates

- Where they go
- The default template
- How Django Vintage selects the template
- The template context

## Where they go

Django Vintage looks for all of its templates within a directory named `vintage`. Typically you will create this directory in your project’s primary template directory, but as long as it is in one of your `TEMPLATE_DIRS` it should work.

## The default template

The default template is named `default.html` and should reside within the `vintage` directory.

Make your vintage default template extend from your project’s base template. Override the appropriate blocks and insert the context variables so they render properly. Here is an example:

    {% extends "base.html" %}
    {% block head_title %}
        {{ object.title }}
    {% endblock head_title %}
    {% block head_metadata %}
        <meta name="description" content="{{ object.metadata.description }}" />
        <meta name="keywords" content="{{ object.metadata.keywords }}" />
        <meta name="author" content="{{ object.metadata.author }}">

        <!--Facebook Metadata /-->
        <meta property="fb:page_id" content="{{ object.metadata.page_id }}" />
        <meta property="og:image" content="{{ object.metadata.image }}" />
        <meta property="og:description" content="{{ object.metadata.description }}"/>
        <meta property="og:title" content="{{ object.metadata.title }}"/>

        <!--Google+ Metadata /-->
        <meta itemprop="name" content="{{ object.metadata.title }}">
        <meta itemprop="description" content="{{ object.metadata.description }}">
        <meta itemprop="image" content="{{ object.metadata.image }}">
    {% endblock head_metadata %}
    {% block content %}
        {{ object.content }}
    {% endblock content %}

## How Django Vintage selects the template

Based on the URL of the requested page, it looks for the most specific to the most generic: For example, a vintage page with the the URL path: `/articles/2010/may/01/bigfoot-sighted/` would look for the following templates, in order:

1. /vintage/articles/2010/may/01/bigfoot-sighted.html
2. /vintage/articles/2010/may/01.html
3. /vintage/articles/2010/may.html
4. /vintage/articles/2010.html
5. /vintage/articles.html
6. /vintage/default.html

## The template context

The context for the template contains only `object`.