Drupal 8使用更新的主題佈局引擎嫩枝。如果您創建了子主題,則可以使用位於<drupalroot>/themes/bootstrap/templates
文件夾中的樹枝文件編輯佈局。任何編輯的文件複製到:<drupalroot>/themes/<bootstrap-sub-theme>/templates
文件夾,然後清除緩存在Drupal:Administration > Configuration > Development > Performance
下面是完整的代碼的情況下,任何人的鬥爭,像我一樣:
文件名:菜單 - 主。 html.twig
{#
/**
* @file
* Default theme implementation to display a menu.
*
* Available variables:
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
* - below: The menu item child items.
* - title: The menu link title.
* - url: The menu link url, instance of \Drupal\Core\Url
* - localized_options: Menu link localized options.
*
* @ingroup templates
*/
#}
{% import _self as menus %}
{#
We call a macro which calls itself to render the full tree.
@see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}
{% macro menu_links(items, attributes, menu_level) %}
{% import _self as menus %}
{% if items %}
{% if menu_level == 0 %}
<div class="container" style="display: flex; justify-content: space-between;">
<ul{{ attributes.addClass('menu', 'nav', 'navbar-nav', 'container') }} style="display: flex; justify-content: space-between;">
{% else %}
<ul{{ attributes.addClass('dropdown-menu') }}>
{% endif %}
{% for item in items %}
{% if menu_level == 0 and item.is_expanded %}
<li{{ item.attributes.addClass('expanded', 'dropdown') }}>
<a href="{{ item.url }}" class="dropdown-toggle" data-target="#" data-toggle="dropdown">{{ item.title }} <span class="caret"></span></a>
{% else %}
<li{{ item.attributes }}>
{{ link(item.title, item.url) }}
{% endif %}
{% if item.below %}
{{ menus.menu_links(item.below, attributes.removeClass('nav', 'navbar-nav'), menu_level + 1) }}
{% endif %}
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endmacro %}
謝謝,但Drupal的8採用了不同的主題引擎(稱爲小枝),並將這些文件不作任何意義,因爲我已經編輯'/ /themes/bootstrap/templates/menu/menu.html .twig'並沒有任何工作。 –
user2470057
您必須在每次更改模板後清除緩存。不知道你是否錯過了這一步。同樣,Drupal7中的命令是'drush cc all' – hailong
UGH!你解決了它。我做了一切正確的,我只是沒有清除緩存。我會標記你的答案是正確的。 – user2470057