Orchard cms扩展菜单项部分

时间:2012-10-04 10:00:37

标签: orchardcms

在果园中扩展菜单部分的最佳方法是什么?

我想对大多数内容类型使用普通菜单部分。

但我也想要一个Custom MainNavigationMenuPart。它包含菜单部分的所有内容,但会向其添加媒体选择器字段和文本字段。 - 这些项目将显示在菜单翻转上。

选项1

我认为这是最好的方式......

我已经看过编写一个自定义菜单部分了 - 但它看起来像菜单部分当前工作的很多功能,我不知道如何最好地以干燥的方式使用它。

我可以将MenuPartItem添加到我的customPart,因此主菜单部件模型看起来像这样

public class MainMenuPart : ContentPart<MainMenuRecord>
    {
        public MenuPart MenuPart { get; set; }

        public string ShortDescription
        {
            get { return Record.ShortDescription; }
            set { Record.ShortDescription = value; }
        }

    }

但是......

  • 如何在部件的编辑器视图中渲染它?
  • 我想使用退出的MenuPartItemEditor。
  • 如何将此信息保存在该部件的记录中?

选项2

我还注意到在菜单部分添加字段(通过cms)。

我的菜单部分现在在后端看起来像这样

enter image description here

这里我根据内容类型自定义了菜单的管理视图。 在 Views / EditorTemplates 中创建 Parts.Navigation.Menu.Edit.cshtml ,在我的自定义中我可以访问菜单部分,但我似乎可以控制显示我添加到零件的文件。 (菜单图像,突出显示和简短描述)

这是自定义Parts.Navigation.Menu.Edit.cshtml(原始版本在Orchard.Core / Navigation / Views / EditorTemplates / Parts.Navigation.Menu.Edit.cshtml中找到)

@model Orchard.Core.Navigation.ViewModels.MenuPartViewModel

@using Orchard.ContentManagement
@using Orchard.Core.Navigation.Models;

@if (!Model.ContentItem.TypeDefinition.Settings.ContainsKey("Stereotype") || Model.ContentItem.TypeDefinition.Settings["Stereotype"] != "MenuItem")
{

    if (Model.ContentItem.ContentType == "StandardIndexPage" ||
        Model.ContentItem.ContentType == "AlternateIndexPage" ||
        Model.ContentItem.ContentType == "MapIndexPage")
    {

        var sd = ((dynamic)Model.ContentItem).MenuPart.ShortDescription;

        @sd

        <fieldset>

            @Html.HiddenFor(m => m.OnMenu, true)
            @Html.HiddenFor(m => m.CurrentMenuId, Model.CurrentMenuId)
            <div>
                <label for="MenuText">@T("Menu text (will appear on main menu)")</label>
                @Html.TextBoxFor(m => m.MenuText, new { @class = "text-box single-line" })
                <span class="hint">@T("The text that should appear in the menu.")</span>
            </div>

        </fieldset>
    }

    else
    {
          <fieldset>

            @Html.EditorFor(m => m.OnMenu)
            <label for="@Html.FieldIdFor(m => m.OnMenu)" class="forcheckbox">@T("Show on menu")</label>
            <div data-controllerid="@Html.FieldIdFor(m => m.OnMenu)" class="">
                <select id="@Html.FieldIdFor(m => m.CurrentMenuId)" name="@Html.FieldNameFor(m => m.CurrentMenuId)">
                    @foreach (ContentItem menu in Model.Menus)
                    {
                        @Html.SelectOption(Model.CurrentMenuId, menu.Id, Html.ItemDisplayText(menu).ToString())
                    }
                </select>
                <span class="hint">@T("Select which menu you want the content item to be displayed on.")</span>

                <label for="MenuText">@T("Menu text")</label>
                @Html.TextBoxFor(m => m.MenuText, new { @class = "text-box single-line" })
                <span class="hint">@T("The text that should appear in the menu.")</span>

            </div>
        </fieldset>    
    }


}
else
{

    <fieldset>
        <label for="MenuText">@T("Menu text")</label>
        @Html.TextBoxFor(m => m.MenuText, new { @class = "textMedium", autofocus = "autofocus" })
        <span class="hint">@T("The text that should appear in the menu.")</span>
        @Html.HiddenFor(m => m.OnMenu, true)
        @Html.HiddenFor(m => m.CurrentMenuId, Request["menuId"])
    </fieldset>

}

我还尝试使用主题

中的placement.info来控制字段的显示

<Match ContentType="StandardIndexPage">
    <Place Fields_Boolean_Edit-Highlight="-"/>
  </Match>

没有成功。

0 个答案:

没有答案
相关问题