Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8534105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:07:04+00:00 2026-06-11T10:07:04+00:00

UPDATE: I’ve changed the original question drastically based on Bertrand’s suggestions and my own

  • 0

UPDATE: I’ve changed the original question drastically based on Bertrand’s suggestions and my own findings. Now it provides an incomplete solution in its text instead of my own blind meanderings and commentary on Orchard, which were completely WRONG!

I need to display a menu using images instead of text, one standard, and another for when hovered/selected. The requirements for the site states that the end-user should be able to manage the menu item images. The standard navigation module now provides an HTML menu item, which is not what the end user wants. The customer wants a very simple, intuitive interface for configuring the sites many menus, and all menus are image-based.

Based on Bertrand’s advice, and after realizing that Content Menu Item IS A CONTENT TYPE, I’ve created a new Content Part in the Admin Interface (not by code, I only want to write code for parts and content types when ultimately needed… I really want to see how far I can go with Orchard just by using the admin interface and templating/CSSing).

So, I’ve created a Menu Image Part, with two Content Picker fields added to it: Image and Hover Image. Then I’ve added this part to the Content Menu Item in the Manage Content Items admin interface.

Since I didn’t write a Driver for it, the Model passed to the menu item template does not have an easily accessible property like @Model.Href… I’ve overriden the MenuItemLink-ContentMenuItem.cshtml with the following code so far:

@using Orchard.Core.Common.Models
@using Orchard.ContentManagement
@{
    var contentManager = WorkContext.Resolve<IContentManager>();
    var itemId = Model.Content.ContentItem.ContentMenuItemPart.Id;
    ContentItem contentItem = contentManager.Get(itemId);
    ContentField temp = null;
    var menuImagePart = contentItem.Parts.FirstOrDefault(p => p.PartDefinition.Name == "MenuImagePart");
    if (menuImagePart != null)
    {
        temp = menuImagePart.Fields.First();
    }
}

<span>@temp</span>
<a href="@Model.Href">@Model.Text</a>

This yields the expected title for the Menu in a link, with a span before it with the following text:

Orchard.Fields.Fields.MediaPickerField 

So all the above code (get the current content manager and the id of the ContentItem representing the ContentMenuItemPart, then use the content manager to get ContentItem itself, then linqing over its Parts to find the MenuImagePart (I can’t use Get to get it because it requires a type and the MenuImagePart is not a type, it was created in the admin interface), then finally getting the first field for debugging purposes (this should be the Image field of the MenuImagePart I’ve created…)… all the above code actually got me to the Media Picker Field on my Meny Image Part…

What I’m not being able to do, and what makes me certainly a lot obtuse and stupid, is to find a way to read the MediaPickerField URL property! I’ve tried casting it to MediaPickerField, but I can’t access its namespace from inside my template code above. I don’t even know which reference to add to my theme to be able to add the following directive to it:

@using Orchard.Fields.Fields

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:07:05+00:00Added an answer on June 11, 2026 at 10:07 am

    I’ve finally succeeded in this task (thanks to Bertrand’s direction).

    UPDATE: And thanks again to Bertrand I’ve polished the solution which was running in circles, querying content items from the content manager when they were already available on the Model… now I’m leveraging the dynamic nature of content item, etc. And I’m finally satisfied with this solution.

    It was necessary to create a new Content Part called Menu Image, then add this to the Content Type named Content Item Menu, and finally overriding the Content Item Menu template. This last part was the really tricky one. If it was not for Bertrand’s directions the code bellow would have been smelly and daunting. The template ended up as follow:

    @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>
    

    The only thing that I didn’t understand is why I can’t use HtmlClassify as an extension method with menu.ContentItem.HtmlClassify() and have to resort to calling the method as a standard static method (see the line with the comment `// !!! for some reason the following code throws´…)

    Thanks again Bertrand!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: I've completely changed the question because in reality, I'm having a really hard
Update 2018 TL;DR; LaTEX for WPF https://github.com/ForNeVeR/wpf-math Original question I need to have a
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
UPDATE: I found a Scipy Recipe based in this question! So, for anyone interested,
Update : I found almost exact similar question , yet it has slightly different
UPDATE This is an old question for an old version of Xcode. It turned
UPDATE: Solution at bottom. I recently switched from using a set up such as
UPDATE: I made a mistake in my debugging - this question is not relavent
Update: I am sorry i pasted in list.xml twice by mistake, my question is
Update 2018 : This question was asked long before PostCSS existed, and I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.