1

I have read and try to reproduce steps from this question/answer How to extend Orchard navigation module to add images to menu items

  1. Have created MenuImagePart with "Image" Content Picker field
  2. Have added this part to "Content Menu Item"
  3. Changed code in MenuItemLink-ContentMenuItem.cshtml

But got next error:

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>
        .@uniqueCSSClassName {
            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>
        .@uniqueCSSClassName: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>

What I done wrong and how should I create this image to add to newly created "Content Menu Item"?

1 Answer 1

0

You have a contentpicker field on there, you want a mediapickerfield (if you are Orchard 1.6).

2
  • Thanks for the answer, but I'm using 1.7.1
    – Volodymyr
    Commented Nov 29, 2013 at 9:29
  • Then you want to use the MediaGalleryField (I believe). ContentPickerField is wrong
    – Hazza
    Commented Nov 29, 2013 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.