dongzhukuai8177 2014-09-06 10:51
浏览 15
已采纳

Smarty Breadcrumbs“链接”问题

I'm looking to create a navigation breadcrumb on my CMS Made Simple site. I'm looking to use smarty/php but I'm having problems making sure it's future-proof - i.e can handle multiple levels.

Here's the sample tree structure I am looking to get working:

-Root
-About us
--Test
---Level 3
-Services
-Contact Us

Here's my code (minus styling):

{assign var="uri" value=$smarty.server.REQUEST_URI|pathinfo}
{assign var="exploded" value="/"|explode:$uri["dirname"]}

<a href="http://{$smarty.server.HTTP_HOST}">Home</a>

{foreach from=$exploded item=element}
 {if $element != ""}

    ::<a href="http://{$smarty.server.HTTP_HOST}/

        {foreach from=$exploded item=element2}
             {if $element2 != ""}
                {$element2}/
             {/if}       
        {/foreach}

     ">{$element|replace:'-':' '}</a>

 {/if}{*close the if blank if*}
{/foreach}
::{$uri["filename"]|replace:'-':' '}

And here's my current output

<a href="http://www.libraryplustrust.org.uk">Home</a>
:: <a href="http://www.libraryplustrust.org.uk/about-us">about us</a>
:: <a href="http://www.libraryplustrust.org.uk/test">test</a>
:: level3

Problem is that the 2nd layer (test) is not being "added on" to the "about-us" parent file. Any ideas would be warmly received.

  • 写回答

1条回答 默认 最新

  • dongya9904 2015-04-22 23:50
    关注

    Instead of writing it yourself, I would suggest using CMS Made Simple's builtin plugin for it:

    {cms_breadcrumbs template="breadcrumbs" root="Root"}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条