Twig 细枝变量似乎超出了过度使用的奏鸣曲模板的范围
我试图覆盖SonataAdminBundle中的默认Twig 细枝变量似乎超出了过度使用的奏鸣曲模板的范围,twig,sonata-admin,symfony-sonata,Twig,Sonata Admin,Symfony Sonata,我试图覆盖SonataAdminBundle中的默认standard_layout.html.twig文件。我希望替换模板扩展我的::base.html.twig。基本上,我已将奏鸣曲块剪切并粘贴到基础模板中的相应块中。这在主仪表板上运行良好。但是,只要我单击一个链接以列出或添加任何实体,就会出现一个错误,表明standard_layout.html.twig顶部声明的变量之一在standard_layout.html.twig中未定义。如果在使用变量之前将{%set\u breadcrumb=
standard_layout.html.twig
文件。我希望替换模板扩展我的::base.html.twig
。基本上,我已将奏鸣曲块剪切并粘贴到基础模板中的相应块中。这在主仪表板上运行良好。但是,只要我单击一个链接以列出或添加任何实体,就会出现一个错误,表明standard_layout.html.twig
顶部声明的变量之一在standard_layout.html.twig
中未定义。如果在使用变量之前将{%set\u breadcrumb=block('breadcrumb'%}
声明(例如)从文件顶部移动到行中,错误将消失,下一个调用的变量将导致相同的错误
这是我当前的standard_layout.html.twig
文件:
{% extends '::base.html.twig' %}
//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') %}
{% block stylesheets %}
{% stylesheets filter='cssrewrite'
'@jqueryui_css'
'@bootstrapeditable_css'
'@main_css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% if admin_pool is defined and admin_pool.getOption('use_select2') %}
{% stylesheets '@select2_css' filter='cssrewrite'%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
<style>
div.select2-container {
margin-left: 0px !important;
}
div.select2-drop ul {
margin: 0px !important;
}
</style>
{% endif %}
{% endblock stylesheets %}
{% block title %}
{{ 'ACC'|trans({}, 'SonataAdminBundle') }}
{% if _title is not empty %}
{{ _title|raw }}
{% else %}
{% if action is defined %}
-
{% for menu in admin.breadcrumbs(action) %}
{% if not loop.first %}
>
{% endif %}
{{ menu.label }}
{% endfor %}
{% endif %}
{% endif%}
{% endblock title %}
{% block body_attributes %}class="sonata-bc {% if _side_menu is empty %}sonata-ba-no-side-menu{% endif %}"{% endblock body_attributes%}
{% block logo %}
<a href="{{ url('sonata_admin_dashboard') }}" id="navtitle">
{{ admin_pool.title }}
</a>
{% endblock %}
{% block navlinks %}
{% block sonata_nav_menu_before %}{% endblock sonata_nav_menu_before%}
{% block sonata_nav_menu %}
{% block top_bar_before_nav %} {% endblock %}
<ul>
{% block sonata_top_bar_nav %}
{% if app.security.token and is_granted('ROLE_SONATA_ADMIN') %}
{% for group in admin_pool.dashboardgroups %}
{% set display = (group.roles is empty or is_granted('ROLE_SUPER_ADMIN') ) %}
{% for role in group.roles if not display %}
{% set display = is_granted(role) %}
{% endfor %}
{# Do not display the group label if no item in group is available #}
{% set item_count = 0 %}
{% if display %}
{% for admin in group.items if item_count == 0 %}
{% if admin.hasroute('list') and admin.isGranted('LIST') %}
{% set item_count = item_count+1 %}
{% endif %}
{% endfor %}
{% endif %}
{% if display and (item_count > 0) %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ group.label|trans({}, group.label_catalogue) }} <span class="caret"></span></a>
<ul class="dropdown-menu">
{% for admin in group.items %}
{% if admin.hasroute('list') and admin.isGranted('LIST') %}
<li{% if app.request.get('_sonata_admin') == admin.code %} class="active"{% endif %}><a href="{{ admin.generateUrl('list')}}">{{ admin.label|trans({}, admin.translationdomain) }}</a></li>
{% endif %}
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}
</ul>
{% block top_bar_after_nav %}{% endblock %}
{% block sonata_top_bar_search %}
{% if app.security.token and is_granted('ROLE_SONATA_ADMIN') %}
<form action="{{ url('sonata_admin_search') }}" method="GET" class="navbar-form navbar-left" role='search'>
<div class="input-append">
<input type="text" name="q" value="{{ app.request.get('q') }}" class="form-control search-query" placeholder="{{ 'search_placeholder'|trans({}, 'SonataAdminBundle') }}">
</div>
</form>
{% endif %}
{% endblock sonata_top_bar_search%}
{% if admin_pool is defined %}
<span class="navbar-right user_block">{% include admin_pool.getTemplate('user_block') %}</span>
{% endif %}
{% endblock sonata_nav_menu%}
{% block sonata_nav_menu_after %}{% endblock %}
{% endblock navlinks %}
{% block content %}
{% block sonata_page_content %}
{% block notice %}
{% include 'SonataCoreBundle:FlashMessage:render.html.twig' %}
{% endblock %}
<div class="row-fluid">
{% block sonata_breadcrumb %}
{% if _breadcrumb is not empty or action is defined %}
<div class="span6">
<ul class="breadcrumb">
{% if _breadcrumb is empty %}
{% if action is defined %}
{% for menu in admin.breadcrumbs(action) %}
{% if not loop.last %}
<li>
{% if menu.uri is not empty %}
<a href="{{ menu.uri }}">{{ menu.label }}</a>
{% else %}
{{ menu.label }}
{% endif %}
<span class="divider">/</span>
</li>
{% else %}
<li class="active">{{ menu.label }}</li>
{% endif %}
{% endfor %}
{% endif %}
{% else %}
{{ _breadcrumb|raw }}
{% endif %}
</ul>
</div>
{% endif %}
{% endblock sonata_breadcrumb %}
{% if _actions is not empty %}
<div class="span4 offset2">
{{ _actions|raw }}
</div>
{% endif %}
</div>
<div class="row-fluid">
{% if _side_menu is not empty %}
<div class="sidebar span2">
<div class="well sonata-ba-side-menu" style="padding: 8px 0;">{{ _side_menu|raw }}</div>
</div>
{% endif %}
<div class="content {{ _side_menu is not empty ? ' span10' : 'span12' }}">
{% block sonata_admin_content %}
{% if _preview is not empty %}
<div class="sonata-ba-preview">{{ _preview|raw }}</div>
{% endif %}
{% if _content is not empty %}
<div class="sonata-ba-content">{{ _content|raw }}</div>
{% endif %}
{% if _show is not empty %}
<div class="sonata-ba-show">{{ _show|raw }}</div>
{% endif %}
{% if _form is not empty %}
<div class="sonata-ba-form">{{ _form|raw }}</div>
{% endif %}
{% if _list_table is not empty or _list_filters is not empty %}
<div class="row-fluid">
<div class="sonata-ba-list {% if _list_filters|trim %}span10{% else %}span12{% endif %}">
{{ _list_table|raw }}
</div>
{% if _list_filters|trim %}
<div class="sonata-ba-filter span2">
{{ _list_filters|raw }}
</div>
{% endif %}
</div>
{% endif %}
{% endblock sonata_admin_content%}
</div>
</div>
{% block footer %}
<div class="row-fluid">
<div class="span2 offset10 pull-right">
<span class="label"><a href="http://sonata-project.org" rel="noreferrer" style="text-decoration: none; color: black">Sonata Project</a></span>
</div>
</div>
{% endblock %}
{% endblock %}
{% endblock content %}
{% block javascripts %}
<script>
window.SONATA_CONFIG = {
CONFIRM_EXIT: {% if admin_pool is defined and admin_pool.getOption('confirm_exit') %}true{% else %}false{% endif %},
USE_SELECT2: {% if admin_pool is defined and admin_pool.getOption('use_select2') %}true{% else %}false{% endif %}
};
window.SONATA_TRANSLATIONS = {
CONFIRM_EXIT: '{{ 'confirm_exit'|trans({}, 'SonataAdminBundle')|escape('js') }}'
};
</script>
{% javascripts
'@jquery_js'
'@jqueryui_js'
'@bootstrap_js'
'@bootstrapeditable_js'
'@jqueryform_js'
filter='?yui_js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% if admin_pool is defined and admin_pool.getOption('use_select2') %}
{% javascripts '@select2_js' %}<script src="{{ asset_url }}"></script>{% endjavascripts %}
{% endif %}
{% if admin_pool is defined and admin_pool.getOption('confirm_exit') %}
{% javascripts '@confirmExit_js' %}<script src="{{ asset_url }}"></script>{% endjavascripts %}
{% endif %}
<script src="{{ asset('bundles/sonataadmin/base.js') }}"></script>
{% endblock %}
{%extends'::base.html.twig%}
//以下是问题变量
{%set\u preview=block('preview')%}
{%set _form=block('form')%}
{%set\u show=block('show')%}
{%set _list _table=block('list _table')%}
{%set{u列表\过滤器=块('list\过滤器')%}
{%set _side_menu=block('side_menu')%}
{%set\u content=block('content')%}
{%set _title=block('title')%}
{%set _breadcrumb=block('breadcrumb')%}
{%set\u actions=block('actions')%}
{%块样式表%}
{%stylesheets过滤器='cssrewite'
“@jqueryui_css”
“@bootstrapeditable_css”
“@main_css”
%}
{%endstylesheets%}
{%如果定义了admin_pool,并且admin_pool.getOption('use_select2')%}
{%stylesheets'@select2_css'filter='cssrewrite'%}
{%endstylesheets%}
div.select2-container{
左边距:0px!重要;
}
div.select2-drop ul{
保证金:0px!重要;
}
{%endif%}
{%endblock样式表%}
{%block title%}
{{'ACC'| trans({},'SonataAdminBundle')}
{%如果_title不是空的%}
{{{u title | raw}}
{%else%}
{%如果定义了操作%}
-
{admin.breadcrumbs(操作)%%中菜单的%
{%if not loop.first%}
{%endif%}
{{menu.label}
{%endfor%}
{%endif%}
{%endif%}
{%endblock title%}
{%block body_attributes%}class=“sonata bc{%if{u side_menu为空%}sonata ba no side menu{%endif%}”{%endblock body_attributes%}
{%block logo%}
{%endblock%}
{%block navlinks%}
{%block sonata_nav_menu_before%}{%endblock sonata_nav_menu before%}
{%block sonata_nav_menu%}
{%block top_bar_前_nav%}{%endblock%}
{%block sonata_top_bar_nav%}
{%如果app.security.token和被授予('ROLE\u SONATA\u ADMIN')%}
{admin_pool.dashboardgroups%中的组的%
{%set display=(group.roles为空或已授予('ROLE\u SUPER\u ADMIN'))%}
{%用于组中的角色。角色如果不显示%}
{%set display=被授予(角色)%}
{%endfor%}
{#如果组中没有可用项,则不显示组标签#}
{%set item_count=0%}
{%if display%}
{如果item_count==0%}
{%if admin.hasroute('list')和admin.isgrated('list')%}
{%set item_count=item_count+1%}
{%endif%}
{%endfor%}
{%endif%}
{%如果显示和(项目计数>0)%}
-
{group.items%中的管理员为%1}
{%if admin.hasroute('list')和admin.isgrated('list')%}
{%endif%}
{%endfor%}
{%endif%}
{%endfor%}
{%endif%}
{%endblock%}
{%block top_bar_后_nav%}{%endblock%}
{%block sonata_top_bar_search%}
{%如果app.security.token和被授予('ROLE\u SONATA\u ADMIN')%}
{%endif%}
{%endblock奏鸣曲\顶部\酒吧\搜索%}
{%如果定义了管理池%}
{%include admin_pool.getTemplate('user_block')%}
{%endif%}
{%endblock奏鸣曲导航菜单%}
{%block sonata_nav_menu_后%}{%endblock%}
{%endblock导航链接%}
{%block content%}
{%block sonata_page_content%}
{%block notice%}
{%include'SonataCoreBundle:FlashMessage:render.html.twig%}
{%endblock%}
{%block sonata_breadcrumb%}
{%如果_breadcrumb不是空的或定义了操作%}
{%如果_面包屑为空%}
{%如果定义了操作%}
{admin.breadcrumbs(操作)%%中菜单的%
{%if not loop.last%}
-