果园CMS:修改菜单项交替和遍历项目 [英] Orchard CMS: Modifying a menu item alternate and iterating over the items

查看:143
本文介绍了果园CMS:修改菜单项交替和遍历项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我创建了名为从管理面板中的主菜单的菜单,我需要自定义默认的标记,例如比方说,我想修改/替换< UL> <李> ,以及周围的<物品> <导航方式> 标签

Let's say I created a menu titled "Main Menu" from the admin panel and I need to customize the default markup, e.g. let's say I want to modify/replace the <ul>, <li> as well as the surrounding <article> and <nav> tags.

我认为我必须要拿出在这样的事情我 Parts.MenuWidget.cshtml 备用模板。

I assume that I have to come up with something like this in my Parts.MenuWidget.cshtml alternate template.

<ul class="a b c">
    for each item in menuItems:
        display("<li>" + item + "</li>")
    end
</ul>

我如何做,在果园?

How do I do that in Orchard?

推荐答案

这是相当简单的。

为你MenuWidget像这样你可以先创建一个备用:

You could first create an alternate for you MenuWidget like so:

Parts.MenuWidget-MyZoneName.cshtml

<nav>
    <div class="logo">
        @Html.Partial("_Logo")
    </div>
    <ul>
        @*Display all the stuff added in the admin*@
        @DisplayChildren(Model.Menu)

        @*Add additional stuff. Of course you could also add it as MenuItem to the Menu-Model*@
        @if ( Request.IsAuthenticated )
        {
            if ( Authorizer.Authorize(StandardPermissions.AccessAdminPanel) )
            {
                <li>
                    <a href="/Admin">
                        Admin
                    </a>
                </li>
            }
            <li>
                <a href="~/Example1">
                    Extra1
                </a>
            </li>
        }
        else
        {
            <li>
                <a href="~/Example2">
                    Extra2
                </a>
            </li>
        }
    </ul>
</nav>

,然后继续做你的MenuItems类似的东西。例如:

And then go on and do something similar for your MenuItems. For example:

MenuItemLink.cshtml

<a href="@Model.Href" class="my-super-cool-custom-link">@Model.Text</a>

这是另一个值得一提的是,你可以只为像上面Me​​nuItemLink特定形状提供替代或只是提供基本菜单项形状将被用于该存在的每一个菜单项类型的替代。

Another thing that's worth mentioning is that you can either only provide an alternate for a specific shape like the MenuItemLink above or just provide an alternate for the base MenuItem shape which will then be used for every MenuItem type that exists.

(也许这些都不是最好的例子,但我猜他们会做的工作;))

(Maybe those are not the best examples, but I guess they'll do the job ;) )

更新
为了删除/修改标签可以为MenuItem.cshtml创建一个备用,并期待在这一部分:

Update: In order to remove/modify the tags you can create an alternate for MenuItem.cshtml and look at this part:

if (HasText(renderedMenuItemLink)) 
{
    var tag = Tag(Model, "li");
    @tag.StartElement
    @renderedMenuItemLink

    if (items.Any()) 
    {
        <ul>
            @DisplayChildren(Model)
        </ul>
    }

    @tag.EndElement
}

这篇关于果园CMS:修改菜单项交替和遍历项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆