【问题标题】:GravCMS - navigation.html.twig dropdown not visibleGravCMS - navigation.html.twig 下拉菜单不可见
【发布时间】:2019-11-02 15:35:13
【问题描述】:

我创建了一个新的基于Pure.css 的 Grav 主题,如 here 所述。

正如他们所说的here15. 下拉菜单应该默认工作。 其实它不适合我。

在呈现的页面中,导航如下所示:

<ul>
  <li class="selected">
    <a href="/">Home </a>
  </li>
  <li class="">
    <a href="/kontakt">Contact</a>
  </li>
</ul>

但是,“主页”应该有 3 个可见的子页面。

有人知道这里可能缺少什么吗?

这是默认的partials/navigation.html.twig

    {% macro loop(page) %}
        {% for p in page.children.visible %}
            {% set current_page = (p.active or p.activeChild) ? 'selected' : '' %}
            {% if p.children.visible.count > 0 %}
                <li class="has-children {{ current_page }}">
                    <a href="{{ p.url }}">
                        {% if p.header.icon %}<i class="fa fa-{{ p.header.icon }}"></i>{% endif %}
                        {{ p.menu }}
                    </a>
                    <ul>
                        {{ _self.loop(p) }}
                    </ul>
                </li>
            {% else %}
                <li class="{{ current_page }}">
                    <a href="{{ p.url }}">
                        {% if p.header.icon %}<i class="fa fa-{{ p.header.icon }}"></i>{% endif %}
                        {{ p.menu }}
                    </a>
                </li>
            {% endif %}
        {% endfor %}
    {% endmacro %}

    <ul>
        {% if theme_config.dropdown.enabled %}
            {{ _self.loop(pages) }}
        {% else %}
            {% for page in pages.children.visible %}
                {% set current_page = (page.active or page.activeChild) ? 'selected' : '' %}
                <li class="{{ current_page }}">
                    <a href="{{ page.url }}">
                        {% if page.header.icon %}<i class="fa fa-{{ page.header.icon }}"></i>{% endif %}
                        {{ page.menu }}
                    </a>
                </li>
            {% endfor %}
        {% endif %}
        {% for mitem in site.menu %}
            <li>
                <a href="{{ mitem.url }}">
                    {% if mitem.icon %}<i class="fa fa-{{ mitem.icon }}"></i>{% endif %}
                    {{ mitem.text }}
                </a>
            </li>
        {% endfor %}
    </ul>

是的,我应该在 GravCMS 论坛中询问。我在 30 天前在那里注册,但我的帐户仍未解锁,也没有管理员回复我的消息。 :)

【问题讨论】:

  • 别人无法为你解决这个问题。您需要确定是否获得所需的数据。在 twig 中启用调试并开始对变量使用 {{ dump() }}

标签: html twig grav


【解决方案1】:

我认为教程有错误...

在模板navigation.html.twig 的第26 行,变量theme_config 被引用。但是,该变量不是标准 Grav 变量,通常在模板中定义为指向 config.theme

要解决您的问题,请将navigation.html.twig 中的theme_config 替换为config.theme 或仅theme

line 26: {% if config.theme.dropdown.enabled %}

变量config.theme 指向文件user/themes/yourtheme/yourtheme.yaml/user/config/themes/yourtheme.yaml。后者用于覆盖来自/user/themes/yourtheme/yourtheme.yaml 的设置,并且在主题更新时不会被覆盖。

有关主题变量的更多信息,请参阅 Grav 文档中的章节 Theme Variables

【讨论】:

    猜你喜欢
    • 2018-10-22
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 2013-06-22
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    相关资源
    最近更新 更多