Javascript 菜单栏活动类Smarty模板
我希望菜单栏根据它所在的页面切换活动类,而不是仅将主页显示为活动类,这仍然是非常新的,谢谢=)(我的网站有smarty模板)Javascript 菜单栏活动类Smarty模板,javascript,html,css,smarty,Javascript,Html,Css,Smarty,我希望菜单栏根据它所在的页面切换活动类,而不是仅将主页显示为活动类,这仍然是非常新的,谢谢=)(我的网站有smarty模板) 要将“active”类应用于不同的元素,您应该执行服务器端更改 请看下页: 您需要的是在Smarty selected页面中进行分配 例如: $smarty->assign('selected_page', 'tour/category.php?id=4'); 在PHP中,您可以使用此$\u服务器['REQUEST\u URI']变量,可能类似以下内容: $sma
要将“active”类应用于不同的
您需要的是在Smarty selected页面中进行分配 例如:
$smarty->assign('selected_page', 'tour/category.php?id=4');
在PHP中,您可以使用此$\u服务器['REQUEST\u URI']
变量,可能类似以下内容:
$smarty->assign('selected_page', substr($_SERVER['REQUEST_URI'],1));
应该行得通
然后在Smarty中:
<div id='cssmenu'>
<ul>
<li {if $selected_page eq 'tour/'}class='active'{/if}><a href='http://www.example.com/tour/'><span>Home</span></a></li>
<li {if $selected_page eq 'tour/category.php?id='}class='active'{/if}><a href='http://www.example.com/tour/category.php?id=4'><span>Photos</span></a></li>
<li {if $selected_page eq 'tour/category.php?id=5'}class='active'{/if}><a href='http://www.example.com/tour/category.php?id=5'><span>Videos</span></a></li>
<li {if $selected_page eq 'tour/category.php?id=59'}class='active'{/if}><a href='http://www.example.com/tour/category.php?id=59'><span>Webcam</span></a></li>
<li {if $selected_page eq 'tour/category.php?id=58'}class='active'{/if}><a href='http://www.example.com/tour/category.php?id=58'><span>Archives</span></a></li>
<li {if $selected_page eq 'tour/pages.php?id=donate'}class='active'{/if}><a href='http://www.example.com/tour/pages.php?id=donate'><span>Donate</span></a></li>
<li {if $selected_page eq 'tour/pages.php?id=join'}class='active'{/if}><a href='http://www.example.com/tour/pages.php?id=join'><span style="color:#EF355C; font-size:20px">JOIN NOW</span></a></li>
<li {if $selected_page eq 'members/'}class='active'{/if}><a href='http://www.example.com/members/'><span style="font-size:18px">Member Login <img src="/tour/images/locky.png"height="22px" width="22px"></span></a> </li>
编辑当然,如果您使用url和锚文本将这些菜单数据放入PHP中的数组会更好。然后,在Smarty中,您可以使用循环来显示菜单,当您将
$selected_page
与链接url进行比较时,您无需编写两次url很抱歉提出了一些新问题,但当您在Smarty或php中说我应该编辑什么文件时?我所有的菜单都在一个名为header.tpl的文件中。另外,我应该将smarty assign和服务器uri放在哪里?谢谢你的帮助!Smarty assign在显示模板文件之前,您应该将它放在PHP文件(PHP而不是TPL)中Marcin我必须在TPL中执行它,它被称为header.TPL,菜单所在的位置,我注意到制作这个的人有一个可以工作的,除了它是纯htlm,他们使用了{literal}命令。。。我现在给你的,但我把它放在header.tpl和index.php中的$marty asign里面,听起来对吗?谢谢你的帮助everything@Eduardof88你应该这样做。
$smarty->assign('selected_page', substr($_SERVER['REQUEST_URI'],1));
<div id='cssmenu'>
<ul>
<li {if $selected_page eq 'tour/'}class='active'{/if}><a href='http://www.example.com/tour/'><span>Home</span></a></li>
<li {if $selected_page eq 'tour/category.php?id='}class='active'{/if}><a href='http://www.example.com/tour/category.php?id=4'><span>Photos</span></a></li>
<li {if $selected_page eq 'tour/category.php?id=5'}class='active'{/if}><a href='http://www.example.com/tour/category.php?id=5'><span>Videos</span></a></li>
<li {if $selected_page eq 'tour/category.php?id=59'}class='active'{/if}><a href='http://www.example.com/tour/category.php?id=59'><span>Webcam</span></a></li>
<li {if $selected_page eq 'tour/category.php?id=58'}class='active'{/if}><a href='http://www.example.com/tour/category.php?id=58'><span>Archives</span></a></li>
<li {if $selected_page eq 'tour/pages.php?id=donate'}class='active'{/if}><a href='http://www.example.com/tour/pages.php?id=donate'><span>Donate</span></a></li>
<li {if $selected_page eq 'tour/pages.php?id=join'}class='active'{/if}><a href='http://www.example.com/tour/pages.php?id=join'><span style="color:#EF355C; font-size:20px">JOIN NOW</span></a></li>
<li {if $selected_page eq 'members/'}class='active'{/if}><a href='http://www.example.com/members/'><span style="font-size:18px">Member Login <img src="/tour/images/locky.png"height="22px" width="22px"></span></a> </li>