.. _tutorial-2: =============== Basic templates =============== Now that we have some sample data to work with we can finally start creating the templates we need to get the site running. .. note:: For more information on what templates Ella uses and what context is passed in, see :ref:`core-views`. ``page/category.html`` ====================== .. highlightlang:: html+django First we will create a template rendering a category: ``page/category.html``. This is a default template that will be used for all categories if their specific template (one with their ``path``) isn't found. The two most important variables in the context we want to use is ``{{ category }}`` containing the ``Category`` model itself and ``{{ listings }}`` containing a list of ``Listing`` objects for that category ordered by ``publish_from`` and/or priority. The basic template will look like::
{{ category.description }}
{% for listing in listings %}{{ listing.target.title }} {{ listing.target.description|safe }}
{% endfor %} That will render the category title, description and a list of objects published in that category. Upon accessing ``/`` you should then see the name of the category and the article you created in :ref:`previous stepPublished on {{ placement.publish_from|date }} in category: {{ category }}
{{ object.description|safe }} This template will have access to the actual ``Publishable`` subclass instance (``Article`` in our case), as opposed to ``page/category.html`` and ``page/listing.html`` which only gets instance of ``Publishable`` by default. Error pages =========== By importing ``handler404`` and ``handler500`` in our ``urls.py``, we turned over the control of error pages to Ella. This means that we need to create two additional templates: ``page/404.html``::