I am trying to override the default standard_layout.html.twig file from the SonataAdminBundle.The new version is in app/Resources/SonataAdmin/views. It extends ::base.html.twig. Essentially, I have cut and pasted Sonata blocks into the appropriate blocks in my base template. This works fine on the main dashboard. But as soon as I click a link to list or add any entity, I get an error indicating that one of the variables declared at the top of standard_layout.html.twig is undefined in standard_layout.html.twig. If I move the {% set _breadcrumb = block('breadcrumb' %} declaration (for example) from the top of the file to the line just before the variable is used, the error goes away and the next called variable causes a similar error.
If I declare my own variables, all child templates have access to them. It's just the sonata variables that are no longer available.
//standard_layout.twig.html
{% extends '::base.html.twig' %}
{% set myvarworks = block('not_a_block_name') %}
//HERE ARE THE PROBLEM VARIABLES
{% set _preview = block('preview') %}
{% set _form = block('form') %}
{% set _show = block('show') %}
{% set _list_table = block('list_table') %}
{% set _list_filters = block('list_filters') %}
{% set _side_menu = block('side_menu') %}
{% set _content = block('content') %}
{% set _title = block('title') %}
{% set _breadcrumb = block('breadcrumb') %}
{% set _actions = block('actions') %}
//dashboard.html.twig
{% dump(myvarworks)%} // empty string
{% dump(_breadcrumb) %} //throws Exception: Variable "_breadcrumb" does not exist
When I look at the block profiler, I notice 2 differences between using the default standard_layout.html.twig and mine:
The default reports 1 real block: sonata.admin.block.admin_list . Mine reports 2 real blocks, both instances of sonata.admin.block.admin_list, but with different ids.
The default reports 2 event blocks: sonata.admin.dashboard.top and sonata.admin.dashboard.bottom. Mine reports the same 2 event blocks, but the pair is called twice (i.e. top, bottom, top, bottom).
Why can't child templates inherit sonata variable from the replacement template? And why are the blocks loaded twice in the replacement template?
Here is a gist of my standard_layout.html.twig file.
I am trying to override the default standard_layout.html.twig file from the SonataAdminBundle.The new version is in app/Resources/SonataAdmin/views. It extends ::base.html.twig. Essentially, I have cut and pasted Sonata blocks into the appropriate blocks in my base template. This works fine on the main dashboard. But as soon as I click a link to list or add any entity, I get an error indicating that one of the variables declared at the top of standard_layout.html.twig is undefined in standard_layout.html.twig. If I move the
{% set _breadcrumb = block('breadcrumb' %}
declaration (for example) from the top of the file to the line just before the variable is used, the error goes away and the next called variable causes a similar error.If I declare my own variables, all child templates have access to them. It's just the sonata variables that are no longer available.
When I look at the block profiler, I notice 2 differences between using the default standard_layout.html.twig and mine:
Why can't child templates inherit sonata variable from the replacement template? And why are the blocks loaded twice in the replacement template?
Here is a gist of my standard_layout.html.twig file.