E
E
Egor2015-09-16 18:46:07
symfony
Egor, 2015-09-16 18:46:07

Value of contexts key in SonataBlockBundle configuration?

SonataAdminBundle needs to sonata_blockbe configured like this:

sonata_block:
    default_contexts: [cms]
    blocks:
        sonata.admin.block.admin_list:
            contexts:  [admin]

You can see the configuration of the sonata-project/sandbox project here . A similar question on stackoverflow sparingly states that context is used to group blocks and you can define your own... Question : Are contexts and , somewhere specially defined or are they just strings? How to set your own context and is it necessary?

cmsadminsonata_page_bundle

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-09-16
@prototype_denis

Sonata works like this:
A route arrives, a CRUD controller is launched on the router, then the ExampleAdmin user service is called. The controller sends the data after the service to the view, and then the simplest magic.

foreach ($this->getBlocksByContext($context) as $block) {
     $data[$block->getName()] = $block->render();
}

return $this->render($template, $data);

In the view, just output in a loop
{% for item in items %}
     {{ item | raw }}
{% endfor %}

That's all.
PS. Of course, the code in the sonata is different, but the principle is the same.
Therefore, by changing the context, we will get the rendering of the blocks belonging to the context.
"cms" and "admin" in sonata are just standard, she uses them.
That is why we will see the sonata.admin.block.admin_list block only in the admin panel, and not on the page of our site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question