CMS简单菜单

时间:2015-12-06 02:34:14

标签: php twitter-bootstrap content-management-system smarty cmsmadesimple

我想从此模板http://ironsummitmedia.github.io/startbootstrap-modern-business/index.html中获取导航菜单,并将其放入我的CMS简单菜单模板中。对我而言,CMS Made Simple的一切都很容易实现,但代码必须用于创建动态菜单。以下是我的一些代码作为起点。

{strip}
{if $count > 0}
<ul class="nav navbar-nav navbar-right">
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{repeat string="<ul class='dropdown'>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{if $node->current == true}
<li><a href="{$node->url}" class="active" {if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->type == 'sectionheader'}
<li>{$node->menutext}

{elseif $node->type == 'separator'}
<li> <hr class="separator" />

{else}
<li><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{/if}

{/foreach}

{repeat string="</li></ul>" times=$node->depth-1}</li></ul>
{/if}
{/strip}

这是我想要生成的导航:

<ul class="nav navbar-nav navbar-right">
<li>
    <a href="about.html">About</a>
</li>
<li>
    <a href="services.html">Services</a>
</li>
<li>
    <a href="contact.html">Contact</a>
</li>
<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Portfolio <b class="caret"></b></a>
    <ul class="dropdown-menu">
        <li>
            <a href="portfolio-1-col.html">1 Column Portfolio</a>
        </li>
        <li>
            <a href="portfolio-2-col.html">2 Column Portfolio</a>
        </li>
        <li>
            <a href="portfolio-3-col.html">3 Column Portfolio</a>
        </li>
        <li>
            <a href="portfolio-4-col.html">4 Column Portfolio</a>
        </li>
        <li>
            <a href="portfolio-item.html">Single Portfolio Item</a>
        </li>
    </ul>
</li>
<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Blog <b class="caret"></b></a>
    <ul class="dropdown-menu">
        <li>
            <a href="blog-home-1.html">Blog Home 1</a>
        </li>
        <li>
            <a href="blog-home-2.html">Blog Home 2</a>
        </li>
        <li>
            <a href="blog-post.html">Blog Post</a>
        </li>
    </ul>
</li>
<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Other Pages <b class="caret"></b></a>
    <ul class="dropdown-menu">
        <li>
            <a href="full-width.html">Full Width Page</a>
        </li>
        <li>
            <a href="sidebar.html">Sidebar Page</a>
        </li>
        <li>
            <a href="faq.html">FAQ</a>
        </li>
        <li>
            <a href="404.html">404</a>
        </li>
        <li>
            <a href="pricing.html">Pricing Table</a>
        </li>
    </ul>
</li>
</ul>

1 个答案:

答案 0 :(得分:0)

我没有看到父母的测试。你需要......

   {if $node->parent == true}

然后你可以得到

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{$node->menutext} <b class="caret"></b></a>