R
R
RSalo2019-07-02 16:57:12
symfony
RSalo, 2019-07-02 16:57:12

Sonata Page pass parameters to block via container?

Hello.
I want to pass parameters from the container to the block, but it does not accept custom parameters. Page service:

class LoginPageService extends DefaultPageService
{

    public function execute(PageInterface $page, Request $request, array $parameters = [], Response $response = null)
    {
        $parameters['test'] = 'test';
        return parent::execute($page, $request, $parameters, $response);
    }
}

Calling the container in the layout:
{{ sonata_page_render_container('content', 'global', {'test': test}) }}

Mistake:
An exception has been thrown during the rendering of a template ("The option "test" does not exist. Defined options are: "attr", "class", "code", "extra_cache_keys", "layout", "manager", "page_id", "template", "ttl", "use_cache".").

The main idea was to use the page service to validate the form and then pass the validated form data to the block. But since I can’t directly transfer the form through the container in Twig, how can I do this? Thanks to!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2019-07-10
@prototype_denis

Options are forwarded to BlockService, so it is necessary to configure custom options in the corresponding block by implementing the configureOptions method.
https://github.com/sonata-project/SonataPageBundle...
Above you can see that the container (the first argument of the twig function) is the block. Redefine the block service or modify an already redefined one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question