[英]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.