Smarty Breadcrumbs“链接”问题

时间:2014-09-06 10:51:12

标签: php smarty breadcrumbs

我想在CMS Made Simple网站上创建导航痕迹。我正在寻找使用smarty / php但我遇到了问题,确保它能够满足未来需求 - 即可以处理多个级别。

以下是我希望工作的示例树结构:

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

这是我的代码(减去样式):

{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:'-':' '}

这是我当前的输出

<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

问题是第二层(测试)没有被“添加”到“about-us”父文件上。任何想法都会受到热烈欢迎。

1 个答案:

答案 0 :(得分:0)

我建议不要自己编写,而是建议使用CMS Made Simple的内置插件:

{cms_breadcrumbs template="breadcrumbs" root="Root"}