Template tags

FeinCMS tags

feincms.templatetags.feincms_tags.feincms_frontend_editing(cms_obj, request)

{% feincms_frontend_editing feincms_page request %}

feincms.templatetags.feincms_tags.feincms_render_content(context, content, request)

{% feincms_render_content content request %}

feincms.templatetags.feincms_tags.feincms_render_region(context, feincms_object, region, request)

{% feincms_render_region feincms_page “main” request %}

feincms.templatetags.feincms_tags.show_content_type_selection_widget(context, region)

{% show_content_type_selection_widget region %}

Thumbnail filters

feincms.templatetags.feincms_thumbnail.cropscale(filename, size='200x200')

Scales the image down and crops it so that its size equals exactly the size passed (as long as the initial image is bigger than the specification).

feincms.templatetags.feincms_thumbnail.thumbnail(filename, size='200x200')

Creates a thumbnail from the image passed, returning its path:

{{ object.image|thumbnail:"400x300" }}
OR
{{ object.image.name|thumbnail:”400x300” }}

You can pass either an ImageField, FileField or the name but not the url attribute of an ImageField or FileField.

The dimensions passed are treated as a bounding box. The aspect ratio of the initial image is preserved. Images aren’t blown up in size if they are already smaller.

Both width and height must be specified. If you do not care about one of them, just set it to an arbitrarily large number:

{{ object.image|thumbnail:"300x999999" }}

Page-module specific tags

class feincms.module.page.templatetags.feincms_page_tags.LanguageLinksNode(tag_name, in_var_name, var_name, args)
{% feincms_languagelinks for feincms_page as links [args] %}

This template tag needs the translations extension.

Arguments can be any combination of:

  • all or existing: Return all languages or only those where a translation exists
  • excludecurrent: Excludes the item in the current language from the list
  • request=request: The current request object, only needed if you are using AppContents and need to append the “extra path”

The default behavior is to return an entry for all languages including the current language.

Example:

{% feincms_languagelinks for feincms_page as links all,excludecurrent %}
{% for key, name, link in links %}
    <a href="{% if link %}{{ link }}{% else %}/{{ key }}/{% endif %}">{% trans name %}</a>
{% endfor %}
class feincms.module.page.templatetags.feincms_page_tags.NavigationNode(tag_name, in_var_name, var_name, args)

Return a list of pages to be used for the navigation

level: 1 = toplevel, 2 = sublevel, 3 = sub-sublevel depth: 1 = only one level, 2 = subpages too extended: run navigation extension on returned pages, not only on top-level node

If you set depth to something else than 1, you might want to look into the tree_info template tag from the mptt_tags library.

Example:

{% feincms_navigation of feincms_page as sublevel level=2,depth=1 %}
{% for p in sublevel %}
    <a href="{{ p.get_absolute_url }}">{{ p.title }}</a>
{% endfor %}
class feincms.module.page.templatetags.feincms_page_tags.ParentLinkNode(tag_name, in_var_name, args)

{% feincms_parentlink of feincms_page level=1 %}

class feincms.module.page.templatetags.feincms_page_tags.TranslatedPageNode(tag_name, in_var_name, var_name, args)
{% feincms_translatedpage for feincms_page as feincms_transpage language=en %}
{% feincms_translatedpage for feincms_page as originalpage %}
{% feincms_translatedpage for some_page as translatedpage language=feincms_page.language %}

This template tag needs the translations extension.

Returns the requested translation of the page if it exists. If the language argument is omitted the primary language will be returned (the first language specified in settings.LANGUAGES).

Note: To distinguish between a bare language code and a variable we check whether settings LANGUAGES contains that code – so naming a variable “en” will probably not do what is intended.

feincms.module.page.templatetags.feincms_page_tags.feincms_breadcrumbs(page, include_self=True)

Generate a list of the page’s ancestors suitable for use as breadcrumb navigation.

By default, generates an unordered list with the id “breadcrumbs” - override breadcrumbs.html to change this.

{% feincms_breadcrumbs feincms_page %}
feincms.module.page.templatetags.feincms_page_tags.feincms_nav(context, feincms_page, level=1, depth=1)

New, simplified version of the {% feincms_navigation %} template tag.

Generally we don’t like abbreviations too much, but the similarity with the HTML5 <nav> tag was just too tempting.

feincms.module.page.templatetags.feincms_page_tags.is_equal_or_parent_of(page1, page2)

Determines whether a given page is equal to or the parent of another page. This is especially handy when generating the navigation. The following example adds a CSS class current to the current main navigation entry:

{% for page in navigation %}
    <a {% if page|is_equal_or_parent_of:feincms_page %}class="current"{% endif %}>
        {{ page.title }}</a>
{% endfor %}
feincms.module.page.templatetags.feincms_page_tags.is_parent_of(page1, page2)

Determines whether a given page is the parent of another page

Example:

{% if page|is_parent_of:feincms_page %} ... {% endif %}
feincms.module.page.templatetags.feincms_page_tags.is_sibling_of(page1, page2)

Determines whether a given page is a sibling of another page

{% if page|is_sibling_of:feincms_page %} ... {% endif %}
feincms.module.page.templatetags.feincms_page_tags.siblings_along_path_to(page_list, page2)

Filters a list of pages so that only those remain that are either:

  • An ancestor of the current page
  • A sibling of an ancestor of the current page

A typical use case is building a navigation menu with the active path to the current page expanded:

{% feincms_nav feincms_page level=1 depth=3 as navitems %}
{% with navitems|siblings_along_path_to:feincms_page as navtree %}
    ... whatever ...
{% endwith %}

ApplicationContent tags

feincms.templatetags.applicationcontent_tags.app_reverse(parser, token)

Returns an absolute URL for applications integrated with ApplicationContent

The tag mostly works the same way as Django’s own {% url %} tag:

{% load applicationcontent_tags %}
{% app_reverse "mymodel_detail" "myapp.urls" arg1 arg2 %}

or

{% load applicationcontent_tags %}
{% app_reverse "mymodel_detail" "myapp.urls" name1=value1 name2=value2 %}

The first argument is a path to a view. The second argument is the URLconf under which this app is known to the ApplicationContent. The second argument may also be a request object if you want to reverse an URL belonging to the current application content.

Other arguments are space-separated values that will be filled in place of positional and keyword arguments in the URL. Don’t mix positional and keyword arguments.

If you want to store the URL in a variable instead of showing it right away you can do so too:

{% app_reverse "mymodel_detail" "myapp.urls" arg1 arg2 as url %}
feincms.templatetags.applicationcontent_tags.feincms_render_region_appcontent(page, region, request)

Render only the application content for the region

This allows template authors to choose whether their page behaves differently when displaying embedded application subpages by doing something like this:

{% if not in_appcontent_subpage %}
    {% feincms_render_region feincms_page "main" request %}
{% else %}
    {% feincms_render_region_appcontent feincms_page "main" request %}
{% endif %}
feincms.templatetags.fragment_tags.fragment(parser, token)

Appends the given content to the fragment. Different modes (replace, append) are available if specified.

Either:

{% fragment request "title" %} content ... {% endfragment %}

or:

{% fragment request "title" (prepend|replace|append) %} content ... {% endfragment %}
feincms.templatetags.fragment_tags.get_fragment(parser, token)

Fetches the content of a fragment.

Either:

{% get_fragment request "title" %}

or:

{% get_fragment request "title" as title %}
feincms.templatetags.fragment_tags.has_fragment(request, identifier)

Returns the content of the fragment, despite its name:

{% if request|has_fragment:"title" %} ... {% endif %}

Table Of Contents

Previous topic

Shortcuts

Next topic

Translations

This Page