Shortcodes

This module contains implementations for the shortcodes content filters

integreat_cms.cms.utils.shortcodes.expand_shortcodes(content: str, context: dict[str, Any] | None = None) str[source]
Parameters:
Return type:

str

Contact

integreat_cms.cms.utils.shortcodes.contact.contact(pargs: list[str], kwargs: dict[str, str], context: dict[str, Any] | None, content: str = '') str[source]

Shortcode to insert a contact card with details from a Contact.

Positional arguments:

  • contact_id – The id of the Contact whose details should be displayed

The remaining positional arguments might be of the following:

  • address (optional) – Whether the address should be shown and other, not explicitly wanted details should be hidden

  • email (optional) – Whether the email address should be shown and other, not explicitly wanted details should be hidden

  • phone_number (optional) – Whether the phone number should be shown and other, not explicitly wanted details should be hidden

  • mobile_phone_number (optional) – Whether the mobile phone number should be shown and other, not explicitly wanted details should be hidden

  • website (optional) – Whether the website should be shown and other, not explicitly wanted details should be hidden

Parameters:
Return type:

str

Page

integreat_cms.cms.utils.shortcodes.page.page(pargs: list[str], kwargs: dict[str, str], context: dict[str, Any] | None, content: str = '') str[source]

Shortcode to insert an internal link to a Page.

Positional arguments:

  • page_id – The id of the Page to which should be linked

  • link_text (optional) – If not given, the title of the public PageTranslation is used

If the target page has an icon set and the shortcode has no link_text, the icon will be included as an <ìmg> before the page title.

Examples

[page 1]

<a href="/augsburg/de/willkommen/">Willkommen</a>

[page 1 "this page"]

<a href="/augsburg/de/willkommen/">this page</a>

[page 999999]

<i>[MISSING LINK]</i>

Parameters:
Return type:

str

Utils

integreat_cms.cms.utils.shortcodes.utils.shortcode(tag: Callable[[P], R] | str | None, endtag: str | None = None) Callable[[Callable[[P], R]], Callable[[P], R]] | Callable[[P], R][source]

Decorator to register a function as a shortcode

For example, this would declare a shortcode cat (taken from the function name), where the first parameter can be 0 or 1 to select between two ASCII cats to insert:

@shortcode
def cat(pargs, kwargs, context, content=""):
    cats = '''
        (=^・ω・^=)
        ฅ/ᐠ- ˕ -マ
    '''.split()
    return cats[pargs[0]]

If the shortcode should use a different keyword than just the name of the function, it can be provided as an argument to the decorator:

@shortcode("ASCII_cat")
def cat(pargs, kwargs, context, content=""):
[…]

When endtag is given, the shortcode will not be atomic but can enclose content between its opening tag and end tag:

@shortcode("cat", "tac")
def cat(pargs, kwargs, context, content=""):
    return f"⚞({content})⚟"

This can then be used as [cat]some <b>feline content</b>[tac].

Parameters:
Return type:

Callable[[Callable[[~P], R]], Callable[[~P], R]] | Callable[[~P], R]