如果当前网址与给定的(树枝)匹配,如何添加活动类

时间:2019-04-22 20:45:41

标签: twig opencart opencart-3

我想为opencart上的商店手动编写侧面菜单,但我遇到一个问题-如何使树枝将“活动”类添加到当前页面的链接中

我试图这样做

<a href="/something/" class="list-group-item {{ (app.request.attributes.get('_route') == 'something') ? 'active' }}">page about something</a>

但它不起作用

2 个答案:

答案 0 :(得分:0)

这正是类别模块的功能,因此您可以复制它:

{% if child.category_id == child_id %}
    <a href="{{ child.href }}" class="list-group-item active">&nbsp;&nbsp;&nbsp;- {{ child.name }}</a> 
{% else %} 
    <a href="{{ child.href }}" class="list-group-item">&nbsp;&nbsp;&nbsp;- {{ child.name }}</a>
{% endif %}

您可以在此处找到上面的文件:

/catalog/view/theme/default/template/extension/module/category.twig

您可以在此处找到其控制器:

/catalog/controller/extension/module/category.php

答案 1 :(得分:-1)

我将通过控制器电话文件将路由请求输入其中。类似于以下内容:

$urlroute = $this->request->get['route'];

然后在树枝文件中,您只需在IF查询中检查route变量

{% if urlroute ==  "something" % }
    <a href="/something/" class="list-group-item active">page about something</a>
{% else %} 
    <a href="/something/" class="list-group-item">page about something</a>
{% endif %}
相关问题