templatetags

ella.core.templatetags.core.do_box(parser, token)

Tag Node representing our idea of a reusable box. It can handle multiple parameters in its body which will then be accessible via {{ box.params }} in the template being rendered.

Note

The inside of the box will be rendered only when redering the box in current context and the object template variable will be present and set to the target of the box.

Author of any Model can specify it’s own box_class which enables custom handling of some content types (boxes for polls for example need some extra information to render properly).

Boxes, same as Views, look for most specific template for a given object an only fall back to more generic template if the more specific one doesn’t exist. The list of templates it looks for:

  • box/category/<tree_path>/content_type/<app>.<model>/<slug>/<box_name>.html
  • box/category/<tree_path>/content_type/<app>.<model>/<box_name>.html
  • box/category/<tree_path>/content_type/<app>.<model>/box.html
  • box/content_type/<app>.<model>/<slug>/<box_name>.html
  • box/content_type/<app>.<model>/<box_name>.html
  • box/content_type/<app>.<model>/box.html
  • box/<box_name>.html
  • box/box.html

Note

Since boxes work for all models (and not just Publishable subclasses), some template names don’t exist for some model classes, for example Photo model doesn’t have a link to Category so that cannot be used.

Boxes are always rendered in current context with added variables:

  • object - object being represented
  • box - instance of ella.core.box.Box

Usage:

{% box <boxtype> for <app.model> with <field> <value> %}
    param_name: value
    param_name_2: {{ some_var }}
{% endbox %}

{% box <boxtype> for <var_name> %}
    ...
{% endbox %}

Parameters:

Option Description
boxtype Name of the box to use
app.model Model class to use
field Field on which to do DB lookup
value Value for DB lookup
var_name Template variable to get the instance from

Examples:

{% box home_listing for articles.article with slug "some-slug" %}{% endbox %}

{% box home_listing for articles.article with pk object_id %}
    template_name : {{object.get_box_template}}
{% endbox %}

{% box home_listing for article %}{% endbox %}
ella.core.templatetags.core.listing(parser, token)

Tag that will obtain listing of top (priority-wise) objects for a given category and store them in context under given name.

Usage:

{% listing <limit>[ from <offset>][of <app.model>[, <app.model>[, ...]]][ for <category> ] [with children|descendents] as <result> [unique [unique_set_name]] %}

Parameters:

Option Description
limit Number of objects to retrieve.
offset Starting with number (1-based), starts from first if no offset specified.
app.model, ... List of allowed models, all if omitted.
category Category of the listing, all categories if not specified. Can be either string (tree path), or variable containing a Category object.
children Include items from direct subcategories.
descendents Include items from all descend subcategories.
result Store the resulting list in context under given name.
unique Unique items across multiple listings.
unique_set_name Name of context variable used to hold the data is optional.

Examples:

{% listing 10 of articles.article for "home_page" as obj_list %}
{% listing 10 of articles.article for category as obj_list %}
{% listing 10 of articles.article for category with children as obj_list %}
{% listing 10 of articles.article for category with descendents as obj_list %}
{% listing 10 from 10 of articles.article as obj_list %}
{% listing 10 of articles.article, photos.photo as obj_list %}

Unique items across multiple listnings::
{% listing 10 for category_uno as obj_list unique %}
{% listing 4 for category_duo as obj_list unique %}
{% listing 10 for category_uno as obj_list unique unique_set_name %}
{% listing 4 for category_duo as obj_list unique unique_set_name %}
ella.core.templatetags.core.do_render(parser, token)
{% render some_var %}

Previous topic

Deploying your Ella application

Next topic

Views

This Page