fluent_contents.rendering¶
This module provides functions to render placeholder content manually.
The functions are available outside the regular templatetags, so it can be called outside the templates as well.
Contents is cached in memcache whenever possible, only the remaining items are queried.
The templatetags also use these functions to render the ContentItem
objects.
-
fluent_contents.rendering.
get_cached_placeholder_output
(parent_object, placeholder_name)¶ Return cached output for a placeholder, if available. This avoids fetching the Placeholder object.
-
fluent_contents.rendering.
render_placeholder
(request, placeholder, parent_object=None, template_name=None, cachable=None, limit_parent_language=True, fallback_language=None)¶ Render a
Placeholder
object. Returns aContentItemOutput
object which contains the HTML output andMedia
object.This function also caches the complete output of the placeholder when all individual items are cacheable.
Parameters: - request (
HttpRequest
) – The current request object. - placeholder (
Placeholder
) – The placeholder object. - parent_object – Optional, the parent object of the placeholder (already implied by the placeholder)
- template_name (str | None) – Optional template name used to concatenate the placeholder output.
- cachable (bool | None) – Whether the output is cachable, otherwise the full output will not be cached. Default: False when using a template, True otherwise.
- limit_parent_language (bool) – Whether the items should be limited to the parent language.
- fallback_language (bool/str) – The fallback language to use if there are no items in the current language. Passing
True
uses the default FLUENT_CONTENTS_DEFAULT_LANGUAGE_CODE.
Return type: - request (
-
fluent_contents.rendering.
render_content_items
(request, items, template_name=None, cachable=None)¶ Render a list of
ContentItem
objects as HTML string. This is a variation of therender_placeholder()
function.Note that the items are not filtered in any way by parent or language. The items are rendered as-is.
Parameters: - request (
HttpRequest
) – The current request object. - items (list or queryset of
ContentItem
.) – The list or queryset of objects to render. Passing a queryset is preferred. - template_name (Optional[str]) – Optional template name used to concatenate the placeholder output.
- cachable (Optional[bool]) – Whether the output is cachable, otherwise the full output will not be cached. Default: False when using a template, True otherwise.
Return type: - request (
-
fluent_contents.rendering.
render_placeholder_search_text
(placeholder, fallback_language=None)¶ Render a
Placeholder
object to search text. This text can be used by an indexer (e.g. haystack) to produce content search for a parent object.Parameters: - placeholder (
Placeholder
) – The placeholder object. - fallback_language (bool|str) – The fallback language to use if there are no items in the current language.
Passing
True
uses the default FLUENT_CONTENTS_DEFAULT_LANGUAGE_CODE.
Return type: - placeholder (
-
fluent_contents.rendering.
get_frontend_media
(request)¶ Return the media that was registered in the request object.
Note
The output of plugins is typically cached. Changes the the registered media only show up after flushing the cache, or re-saving the items (which flushes the cache).
-
fluent_contents.rendering.
register_frontend_media
(request, media)¶ Add a
Media
class to the current request. This will be rendered by therender_plugin_media
template tag.
-
fluent_contents.rendering.
is_edit_mode
(request)¶ Return whether edit mode is enabled; output is wrapped in
<div>
elements with metadata for frontend editing.
-
fluent_contents.rendering.
set_edit_mode
(request, state)¶ Enable the edit mode; placeholders and plugins will be wrapped in a
<div>
that exposes metadata for frontend editing.