[英]Joomla 3 menu active state not working
我的joomla 3有问题。
我使用自定义模板制作菜单,该模板位于/templates/mytemplate/html/mod_menu/mainmenu.php
但是,当我继续菜单中的任何链接时,“ active”的数组索引始终为false。
例如,当前页面是http://localhost/about.html
并在数组中的“活动”索引为空
[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] =>
)
从基本mod_menu
文件的外观来看,加载菜单的助手总是将active属性设置为false
,而是使用自己的检查来查看活动的内容。 即,基本的mod_menu.php
文件设置以下值:
$list = ModMenuHelper::getList($params);
$base = ModMenuHelper::getBase($params);
$active = ModMenuHelper::getActive($params);
$active_id = $active->id;
$path = $base->tree;
因此active_id
将包含当前菜单项的ID。 因此,如果您想要当前菜单,可以像这样检查:
foreach ($list as $i => &$item) :
if ($item->id == $active_id) {
// do something with active item
}
....
}
$list
由主文件设置,因此可以在布局文件中访问。
您还可以通过以下检查在同一foreach循环中检查活动项目上方的父项目:
if (in_array($item->id, $path)) {}
从技术上讲,您可以运行第一个foreach
循环,并根据需要将$item->active
设置为true
。 但是,到那时,您可能已经完成了您想要的商品!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.