DegDitor Twig Functions Reference


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.

Params:
  • attributeId (string, required)
  • valuesMap (array<int|string,string>, optional - values mapping)

Example:
1{{ get_block_attribute('alignment', { 2 'left': 'text-start', 3 'right': 'text-end' 4}) }} 5

Attributes can be fetched also manually from the block_data object, e.g.
{% set title = block_data.attributes.title ?? '' %}

get_block_parent

Returns the parent block of the current or given block. Useful for conditional rendering based on hierarchy.

Params:
  • block (BlockInterface, optional - if not set, the current block from twig context will be used)

Example:
1{% set parent = get_block_parent() %} 2{% if parent and parent.type == 'carousel_block' %} 3 ... 4{% endif %} 5

Utility functions and filters

get_category_path_prefix

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<div class="{{ cn('base-class', custom_class, condition ? 'active' : '') }}"></div> 4
Outputs:
<div class="base-class active"></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.
Three, two, one...

Ready for DegDitor?

Try the plugin

Experience the best features at no cost

Get a better understanding of DegDitor and how it works

Test it risk-free and see the results

Try it

Get a demo

Get a personalized demo tailored to your unique needs

Preview our pricing plans

Evaluate DegDitor against your requirements

Get a demo

We are here for you

After months of intense development, it’s time to put DegDitor to work. For feedback, questions or information please contact us!

Contact us