Documentation » Block

3. Provided Blocks »

« 1. Installation

2. Twig Helpers

SonataBlockBundle provides several Twig helper functions to allow easier interaction with blocks:

Render a block from its instance:

{{ sonata_block_render(block) }}

Render a block by providing the block’s type and options:

{{ sonata_block_render({ 'type': 'sonata.block.service.rss' }, {
    'title': 'Sonata Project\'s Feeds',
    'url': ''
}) }}

Render a block by providing the block’s cache options:

{{ sonata_block_render(block, {
    'use_cache': use_cache,
    'extra_cache_key': extra_cache_key
}) }}

Render a block by calling an event:

{{ sonata_block_render_event('node.comment', {
    'target': post
}) }}


Review the Events section for more information: Events

Rendering a block related to javascripts and stylesheets for the current page implies the helpers to be called at the end of the page:

{{ sonata_block_include_stylesheets('screen', app.request.basePath) }}
{{ sonata_block_include_javascripts('screen', app.request.basePath) }}

The app.request.basePath must be provided if your application is stored in a sub-folder.

Found a typo? Something is wrong in this documentation? Just fork and edit it!