2013-11-25 23 views
1

我已閱讀並嘗試重現步驟從這個提問/回答How to extend Orchard navigation module to add images to menu items如何在果園添加圖像,而不是文本內容菜單項1.7.1

  1. 已創建MenuImagePart與「圖像」內容選擇器領域
  2. 已經加入此部分 「內容菜單項」
  3. 更改代碼MenuItemLink-ContentMenuItem.cshtml

卻得到了一個錯誤:

https://dl.dropboxusercontent.com/u/86009304/MenuImagePart.png

@using Orchard.Utility.Extensions; 
@using System.Dynamic 
@{ 

/* Getting the menu content item 
***************************************************************/ 

var menu = Model.Content.ContentItem; 

/* Creating a unique CSS class name based on the menu item 
***************************************************************/ 

// !!! for some reason the following code throws: 'string' does not contain a definition for 'HtmlClassify' 
//string test = menu.ContentType.HtmlClassify(); 
string cssPrefix = Orchard.Utility.Extensions.StringExtensions.HtmlClassify(menu.ContentType); 
var uniqueCSSClassName = cssPrefix + '-' + Model.Menu.MenuName; 
/* Adds the normal and hovered styles to the html if any 
***************************************************************/ 
if (menu.MenuImagePart != null) 
{ 
    if (!string.IsNullOrWhiteSpace(menu.MenuImagePart.Image.Url)) 
    { 
    using(Script.Head()){ 
    <style> 
     [email protected] { 
      background-image: url('@Href(menu.MenuImagePart.Image.Url)'); 
      width: @{@menu.MenuImagePart.Image.Width}px; 
      height: @{@menu.MenuImagePart.Image.Height}px; 
      display: block; 
     } 
    </style> 
    } 
    } 
    if (!string.IsNullOrWhiteSpace(menu.MenuImagePart.HoverImage.Url)) 
    { 
    using(Script.Head()){ 
    <style> 
     [email protected]:hover { 
      background-image: url('@Href(menu.MenuImagePart.HoverImage.Url)'); 
      width: @{@menu.MenuImagePart.HoverImage.Width}px; 
      height: @{@menu.MenuImagePart.HoverImage.Height}px; 
     } 
    </style>  
    } 
    } 
} 
}  
<a class="@uniqueCSSClassName" href="@Model.Href">@Model.Text</a> 

我做錯了,我應該如何創建這個圖像添加到新創建的「內容菜單項」?

回答

0

你有一個contentpicker字段,你想要一個mediapickerfield(如果你是果園1.6)。

+0

感謝您的回答,但我使用的是1.7.1 – Vova

+0

然後你想使用MediaGalleryField(我相信)。 ContentPickerField錯誤 – Hazza

相關問題