Template tags (feincms3.templatetags.feincms3)

feincms3.templatetags.feincms3.maybe_target_blank(href, *, attributes='target="_blank" rel="noopener"')[source]

Return the value of attributes if the first argument isn’t a first party link (as determined by is_first_party_link())

Usage:

<a href="{{ url }}" {% maybe_target_blank url %}>...</a>
feincms3.templatetags.feincms3.render_region(context, regions, region, **kwargs)[source]

Render a single region. See RegionRenderer for additional details.

Usage:

{% render_region regions "main" %}
feincms3.templatetags.feincms3.reverse_app(parser, token)[source]

Reverse app URLs, preferring the active language.

Usage:

{% load feincms3 %}
{% reverse_app 'blog' 'detail' [args] [kw=args] [fallback='/'] %}

namespaces can either be a list or a comma-separated list of namespaces. NoReverseMatch exceptions can be avoided by providing a fallback as a keyword argument or by saving the result in a variable, similar to {% url 'view' as url %} does:

{% reverse_app 'newsletter' 'subscribe-form' fallback='/newsletter/' %}

Or:

{% reverse_app 'extranet' 'login' as login_url %}
feincms3.templatetags.feincms3.reverse_passthru(parser, token)[source]

Reverse a passthru app URL, preferring the active language.

Usage:

{% load feincms3 %}
{% reverse_passthru 'imprint' [fallback='/'] %}

This is the template tag version of reverse_passthru(). It saves you from having to know that the view inside the passthru URLconf is called passthru; the tag above is exactly equivalent to:

{% reverse_app 'imprint' 'passthru' %}

Passthru pages may simply not have been created yet, which makes the {% ... as var %} form – it assigns an empty string instead of raising NoReverseMatch – the most useful one here:

{% reverse_passthru 'imprint' as imprint_url %}
{% if imprint_url %}<a href="{{ imprint_url }}">{% translate "Imprint" %}</a>{% endif %}

A fallback keyword argument is supported as well.

feincms3.templatetags.feincms3.translations(iterable, languages=None)[source]

Return a list of dictionaries, one for each language in settings.LANGUAGES. An example follows:

[
    {"code": "en", "name": "English", "object": <instance>},
    {"code": "de", "name": "German", "object": None},
    # ...
]

The filter accepts anything you throw at it. “It” should be an iterable of objects having a language_code property however, or anything non-iterable (such as None). The filter always returns a list of all languages in settings.LANGUAGES but the object key’s value will always be None if the data is unusable.

feincms3.templatetags.feincms3.translations_from(*iterables, languages=None)[source]

Return a list of dictionaries, one for each language in settings.LANGUAGES, built from several sources of translations.

This is the counterpart to the translations() filter for the case where more than one object may provide the translation for a given language. The iterables are applied in order and later ones win, so the most specific source goes last:

{% load feincms3 %}
{% translations_from page.translations.active article.translations.active as languages %}
<nav class="languages">
  {% for lang in languages %}
    <a href="{% if lang.object %}{{ lang.object.get_absolute_url }}{% else %}/{{ lang.code }}/{% endif %}">
      {{ lang.name }}
    </a>
  {% endfor %}
</nav>

The menu above links the translated article where one exists and falls back to the translated page everywhere else. The return value has the same shape as the one from translations():

[
    {"code": "en", "name": "English", "object": <instance>},
    {"code": "de", "name": "German", "object": None},
    # ...
]

Arguments which are falsy or which are strings are skipped, and objects whose language_code isn’t in the list of languages are ignored, so neither optional objects nor rows in a language which has since been removed from the setting have to be guarded against at the call site. Pass a languages keyword argument containing a list of (code, name) tuples to override the set of languages.