gpt4 book ai didi

javascript - 在(autonav)模板Concrete5中显示自定义属性

转载 作者:行者123 更新时间:2023-12-02 23:01:37 25 4
gpt4 key购买 nike

我想在导航中显示 2 个自定义属性。因此,我创建了属性 nav_item_classbeschrijving

属性nav_item_class显示页面图标并正常工作。所有导航项上的属性 beschrijving(描述)都是相同的。它应该显示不同页面的不同属性,而不是在所有导航项中添加的最后一个属性。


<?php View::getInstance()->requireAsset('javascript', 'jquery');

$navItems = $controller->getNavItems();

foreach ($navItems as $ni) {
$classes = array();


if ($ni->isCurrent) {
//class for the page currently being viewed
$classes[] = 'nav-selected';
}

if ($ni->inPath) {
//class for parent items of the page currently being viewed
$classes[] = 'nav-path-selected';
}


if ($ni->hasSubmenu) {
//class for items that have dropdown sub-menus
$classes[] = 'dropdown';
}

if (!empty($ni->attrClass)) {
//class that can be set by end-user via the 'nav_item_class' custom page attribute
$classes[] = $ni->attrClass;
}

if ($ni->cObj->getAttribute('beschrijving')) {
//custom beschrijving
$beschrijving = $ni->cObj->getAttribute('beschrijving');
}

//Put all classes together into one space-separated string
$ni->classes = implode(" ", $classes);
}

//*** Step 2 of 2: Output menu HTML ***/

echo '<ul class="nav navbar-nav navbar-right">'; //opens the top-level menu

foreach ($navItems as $ni) {

echo '<li class="' . $ni->classes . '">'; //opens a nav item

if ($ni->isEnabled) {
$ni->hasSubmenu;
}

if ($ni->hasSubmenu) {
echo '<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">' . $ni->name . '</a>';
} else {
echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '"><span class="navwrap"><span class="navimg"><i class="material-icons">' . $ni->attrClass . '</i></span><span class="navtit">' . $ni->name . '</span><span class="navtxt">' . $beschrijving . '</span></span></a>';
}

if ($ni->hasSubmenu) {
echo '<ul class="dropdown-menu">'; //opens a dropdown sub-menu
} else {
echo '</li>'; //closes a nav item
echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s)
}
}

echo '</ul>'; //closes the top-level menu

我想要什么:

(主页图标)- 主页、主页描述

(信息图标)- 信息、信息描述

(联系人图标)- 信息、联系人描述

等等

发生了什么:

(主页图标)- 主页、联系人描述

(信息图标)- 信息、联系方式描述

(联系人图标)- 联系人、联系人描述

最佳答案

您在这里所做的是,在循环 navItems 时分配一个变量。然后你进一步并再次循环 navItems。在此循环中,变量具有最后一个 navItem 的值。您需要做的是,在第一个循环上将属性值分配给 navItem。 navItem 是一个简单的 php StdClass 对象,可以分配新变量,您可以稍后检索。

第一个循环中的内容如下:

foreach ($navItems as $ni) {
$classes = array();


if ($ni->isCurrent) {
//class for the page currently being viewed
$classes[] = 'nav-selected';
}

if ($ni->inPath) {
//class for parent items of the page currently being viewed
$classes[] = 'nav-path-selected';
}


if ($ni->hasSubmenu) {
//class for items that have dropdown sub-menus
$classes[] = 'dropdown';
}

if (!empty($ni->attrClass)) {
//class that can be set by end-user via the 'nav_item_class' custom page attribute
$classes[] = $ni->attrClass;
}

if ($ni->cObj->getAttribute('beschrijving')) {
//custom beschrijving
$ni->beschrijving = $ni->cObj->getAttribute('beschrijving');
} else {
$ni->beschrijving = '';
}

//Put all classes together into one space-separated string
$ni->classes = implode(" ", $classes);
}

然后在第二个循环中:

foreach ($navItems as $ni) {

echo '<li class="' . $ni->classes . '">'; //opens a nav item

if ($ni->isEnabled) {
$ni->hasSubmenu;
}

if ($ni->hasSubmenu) {
echo '<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">' . $ni->name . '</a>';
} else {
echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '"><span class="navwrap"><span class="navimg"><i class="material-icons">' . $ni->attrClass . '</i></span><span class="navtit">' . $ni->name . '</span><span class="navtxt">' . $ni->beschrijving . '</span></span></a>';
}

if ($ni->hasSubmenu) {
echo '<ul class="dropdown-menu">'; //opens a dropdown sub-menu
} else {
echo '</li>'; //closes a nav item
echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s)
}
}

关于javascript - 在(autonav)模板Concrete5中显示自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57759260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com