0

例如,当我运行标准搜索时,/search?q=querystring可用的 url 指向根目录:

// dump of the twig url variable:
array:1 [▼
  "de" => "/"
]

这导致我的菜单突出显示主页链接,这当然是不正确的;) - 有没有一种区分搜索页面和实际首页的好方法?

4

1 回答 1

1

这对我来说看起来像一个错误,但你可以使用path变量来检查它是否真的是一个页面模板,例如

{% if path is defined %}

不要让 path 变量的内容混淆您的内容页面在 phpcr 树中的位置,因此它不代表 url。在某些情况下,它确实与 url 匹配。在大多数情况下,如果您使用其他资源定位器策略作为默认树策略,路径变量是检查页面是否是另一个页面的子页面的好方法。

例如,如果您创建导航:

{% for page in sulu_navigation_root_tree('main') %}
    {% set addClass = '' %}
    {% if page.path starts with path|default() %}
        {% set addClass = 'is-active-parent' %}
    {% elseif page.uuid == uuid|default() %}
        {% set addClass = 'is-active' %}
    {% endif %}

    {# ... #}
{% endfor %}
于 2019-06-11T07:14:22.437 回答