[英]Joomla 3 menu active state not working
I have a problem with joomla 3. 我的joomla 3有问题。
I make menu using the custom template is located in the /templates/mytemplate/html/mod_menu/mainmenu.php 我使用自定义模板制作菜单,该模板位于/templates/mytemplate/html/mod_menu/mainmenu.php
But when I go on any link in the menu, then the array index of "active" is always false. 但是,当我继续菜单中的任何链接时,“ active”的数组索引始终为false。
For example, curent page is http://localhost/about.html
例如,当前页面是
http://localhost/about.html
and in the array "active" index is empty 并在数组中的“活动”索引为空
[1] => stdClass Object
(
[id] => 102
[menutype] => mainmenu
[title] => О проекте
[alias] => about
[note] =>
[route] => about
[link] => index.php?option=com_content&view=article&id=1
[type] => component
[level] => 1
[language] => *
[browserNav] => 0
[access] => 1
[params] => JRegistry Object
(
[data:protected] => stdClass Object
(
[show_title] =>
[link_titles] =>
[show_intro] =>
[info_block_position] =>
[show_category] =>
[link_category] =>
[show_parent_category] =>
[link_parent_category] =>
[show_author] =>
[link_author] =>
[show_create_date] =>
[show_modify_date] =>
[show_publish_date] =>
[show_item_navigation] =>
[show_vote] =>
[show_tags] =>
[show_icons] =>
[show_print_icon] =>
[show_email_icon] =>
[show_hits] =>
[show_noauth] =>
[urls_position] =>
[menu-anchor_title] =>
[menu-anchor_css] =>
[menu_image] =>
[menu_text] => 1
[page_title] =>
[show_page_heading] => 0
[page_heading] =>
[pageclass_sfx] =>
[menu-meta_description] =>
[menu-meta_keywords] =>
[robots] =>
[secure] => 0
)
)
[home] => 0
[img] =>
[template_style_id] => 0
[component_id] => 22
[parent_id] => 1
[component] => com_content
[tree] => Array
(
[0] => 102
)
[query] => Array
(
[option] => com_content
[view] => article
[id] => 1
)
[deeper] =>
[shallower] =>
[level_diff] => 0
[parent] =>
this empty [active] =>
[flink] => /about.html
[anchor_css] =>
[anchor_title] =>
[menu_image] =>
)
From the looks of the base mod_menu
files, the active property is always set to false
by the helper that loads the menu and instead they use their own checks to see what is active. 从基本
mod_menu
文件的外观来看,加载菜单的助手总是将active属性设置为false
,而是使用自己的检查来查看活动的内容。 Namely, the base mod_menu.php
file sets these values: 即,基本的
mod_menu.php
文件设置以下值:
$list = ModMenuHelper::getList($params);
$base = ModMenuHelper::getBase($params);
$active = ModMenuHelper::getActive($params);
$active_id = $active->id;
$path = $base->tree;
So active_id
will contain the id of the current menu item. 因此
active_id
将包含当前菜单项的ID。 Thus if you want the current menu you can check like this: 因此,如果您想要当前菜单,可以像这样检查:
foreach ($list as $i => &$item) :
if ($item->id == $active_id) {
// do something with active item
}
....
}
$list
is set by the main file, so that is accessible in your layout file. $list
由主文件设置,因此可以在布局文件中访问。
You can also check for parent items above the active item in the same foreach loop with this check: 您还可以通过以下检查在同一foreach循环中检查活动项目上方的父项目:
if (in_array($item->id, $path)) {}
Technically you could run the first foreach
loop and set $item->active
to true
if you wanted. 从技术上讲,您可以运行第一个
foreach
循环,并根据需要将$item->active
设置为true
。 However, at that point you probably could just have done what you wanted with the item! 但是,到那时,您可能已经完成了您想要的商品!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.