我正在尝试实现下面的菜单,但由于某种原因,如果我导航到3级和4级,它不显示菜单的中间部分(2级和3级)。如果我在3级然后1 ,2,3应该是可见的。如果我在4级,那么所有级别。这就是我想要实现的目标。
我阅读了整个templating documentation,this post以及更多内容,但无法找到为什么我的代码无效。
预期:
FRONTEND - BACKEND
----------------------
COUNTRY | LEAGUE -> After selecting FRONTEND in level 1 above
----------------------
INDEX | LIST | CREATE -> After selecting COUNTRY in level 2 above
----------------------
Countries will appear here after selecting LIST in level 3 above
我失败的尝试:
FRONTEND - BACKEND
----------------------
INDEX | LIST | CREATE -> After selecting COUNTRY in level 2 above
----------------------
或
FRONTEND - BACKEND
----------------------
Countries will appear here after selecting LIST in level 3 above
base.html.twig
Football
BackendBundle
.....
FrontendBundle
Resources
views
Default
index.html.twig
Country
index.html.twig
list.html.twig
base.html.twig
<body>
<a href="{{ path('football_frontend_default_index') }}">FRONTEND</a>
‐
<a href="{{ path('football_backend_default_index') }}">BACKEND</a>
<hr />
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
</body>
默认/ index.html.twig
{% extends '::base.html.twig' %}
{% block body %}
{% spaceless %}
<a href="{{ path('football_frontend_country_index') }}">COUNTRY</a>
|
<a href="{{ path('football_frontend_league_index') }}">LEAGUE</a>
<hr />
{% endspaceless %}
{% endblock %}
国家/ inedx.html.twig
{% extends 'FootballFrontendBundle:Default:index.html.twig' %}
{% block body %}
{% spaceless %}
<a href="{{ path('football_frontend_country_index') }}">Index</a>
|
<a href="{{ path('football_frontend_country_list') }}">List</a>
|
<a href="{{ path('football_frontend_country_create') }}">create</a>
<hr />
{% endspaceless %}
{% endblock %}
国家/ list.html.twig
{% extends 'FootballFrontendBundle:Country:index.html.twig' %}
{% block body %}
{% spaceless %}
COUNTRY - List
<hr />
....
{% endspaceless %}
{% endblock %}
答案 0 :(得分:1)
当您在文件body
中使用Country/list.html.twig
块时,替换根文件base.html.twig
中的块。它与PHP中的方法继承相同。如果你想做你想做的事,你有两种方法:
E.g。
默认/ index.html.twig 强>
{% extends '::base.html.twig' %}
{% block body %}
{% spaceless %}
<a href="{{ path('football_frontend_country_index') }}">COUNTRY</a>
|
<a href="{{ path('football_frontend_league_index') }}">LEAGUE</a>
<hr />
{% endspaceless %}
{% block body2 %}{% endblock %}
{% endblock %}
<强>国家/ inedx.html.twig 强>
{% extends 'FootballFrontendBundle:Default:index.html.twig' %}
{% block body2 %}
{% spaceless %}
<a href="{{ path('football_frontend_country_index') }}">Index</a>
|
<a href="{{ path('football_frontend_country_list') }}">List</a>
|
<a href="{{ path('football_frontend_country_create') }}">create</a>
<hr />
{% endspaceless %}
{% block body3 %}{% endblock %}
{% endblock %}