Skip to content

Templates

Sundar Raman edited this page Feb 1, 2012 · 4 revisions

Templates are rendered with the Jinja template engine.

Overview

There is a template for each page of the application found in the templates/ directory. There are then some partials that are used for abstracted output in the templates/partials/ directory.

Template Data

Template data is passed along from the Controller.render().

All config data from config.yaml is available in two forms. If there was value defined in the config file like:

var:
    sub_var:
        sub_sub_var: 'value'

This would be available like:

  • {{ d.config.var.sub_var.sub_sub_var }} (nested dict in the config space)
    • Please use this style going forward in your templates, as this ensures that other data will not be overwritten.
  • {{ d.var_sub_var_sub_sub_var }} (flat style variable)

New Page

For a whole, new page, use the following. The first part will use the base.html template as the container for the page.

{% extends "./partials/base.html" %}

Define the title block, as this will set the title of the page.

{% block title %} CMS Admin Settings {% endblock title %}

Define the continent block which will be the main content of the page.

{% block continent %}
   <div>Main content here.</div>
{% endblock continent %}

You can also add Javascript files by defining the page_js block.

{% block page_js %}
  <script type='text/javascript' src="/static/js/js_file.js"></script>
{% endblock page_js %}

Default and City-Specific About page

The /about resource tries to load a matching template in the following order: /templates/<city_id>_about.html /templates/about.html

A city-specific example would be /templates/nyc_about.html. If neither are found, then /about will return a 404 Note that this is a new feature, and not available in older versions of the codebase.