The DegditorBlocksExtension exposes a set of custom Twig functions that power dynamic block rendering, attribute access, layout composition, and more. Below is a breakdown of each available function and how to use it.
🔧 Available Twig Functions
Rendering functions
render_page_blocks
Renders all root-level blocks of the given page. Use in page templates as an entry point to recursively render all blocks.
Params:
page (PageInterface, required - the page to be rendered)
additionalData (array<string,mixed>, optional - additional data to be passed to root blocks)
tag (string, optional - HTML tag that will wrap each root block)
domElementAttributes (array<string,string>, optional - dom attributes to be passed to each root block)
Example:
{{ render_page_blocks(page) }}
render_block_children
Renders all child blocks of the current block or a given one.
Params:
block (BlockInterface, optional - if not set, the current block from twig context will be used)
additionalData (array<string,mixed>, optional - additional data to be passed to rendered blocks)
tag (string, optional - HTML tag that will wrap each rendered block)
domElementAttributes (array<string,string>, optional - dom attributes to be passed to each rendered block)
Example:
render_block_children()
render_block
Useful for manually rendering nested content inside a custom structure.
Params:
block (BlockInterface, required)
additionalData (array<string,mixed>, optional - additional data to be passed to rendered block)
tag (string, optional - HTML tag that will wrap the rendered block)
domElementAttributes (array<string,string>, optional - dom attributes to be passed to the rendered block)
Example:
1{% set children = get_block_children() %}2{% for child_block in children %}3 render_block(child_block)
4{% endfor %}5
get_block_children
Returns an array of child blocks for programmatic rendering.
Params:
block (BlockInterface, optional - if not set, the current block from twig context will be used)
Example:
1{% set slides = get_block_children() %}2{% for slide in slides %}3{{ render_block(slide) }}4{% endfor %}5
get_block_attribute
Retrieves an attribute value from the current block context.
Returns the configured prefix for category URLs. See routing docs.
Example:
get_category_path_prefix()
get_page_path_prefix
Returns the configured prefix for page URLs. See routing docs.
Example:
get_page_path_prefix()
cn
Utility function to merge class names and remove empty/duplicate values.
Params:
classNames (...string[], optional - list of strings to be merged)
Example:
1{% set custom_class = null %}2{% set condition = true %}3<divclass="{{ cn('base-class', custom_class, condition ? 'active' : '') }}"></div>4
Outputs:
<div class="base-classactive"></div>
degditor_img_relative_resize
Filter used to relative resize an image. Useful to generate image srcset attribute, see MDN reference.
Params:
width (int, required - the resized width of the image, in pixel)
{% set resized_src = source|degditor_img_relative_resize(width) %}
✅ Notes on Usage
Functions like get_block_attribute, get_block_children, and get_block_parent require the block_data and block_entity context to be available (injected automatically inside block templates).
The extension handles caching internally for performance.
Preview mode is auto-detected via a _preview_token query param.