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"}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库