Template tags (feincms3.templatetags.feincms3)¶
- feincms3.templatetags.feincms3.maybe_target_blank(href, *, attributes='target="_blank" rel="noopener"')[source]¶
Return the value of
attributesif the first argument isn’t a first party link (as determined byis_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
RegionRendererfor 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='/'] %}
namespacescan either be a list or a comma-separated list of namespaces.NoReverseMatchexceptions can be avoided by providing afallbackas 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 calledpassthru; 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 raisingNoReverseMatch– the most useful one here:{% reverse_passthru 'imprint' as imprint_url %} {% if imprint_url %}<a href="{{ imprint_url }}">{% translate "Imprint" %}</a>{% endif %}
A
fallbackkeyword 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_codeproperty however, or anything non-iterable (such asNone). The filter always returns a list of all languages insettings.LANGUAGESbut theobjectkey’s value will always beNoneif 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_codeisn’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 alanguageskeyword argument containing a list of(code, name)tuples to override the set of languages.