+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Use image from a page custom field in navigation widget

Use image from a page custom field in navigation widget

3 posts, 1 answered
  1. David
    David avatar
    0 posts
    Registered:
    18 Sep 2016
    26 Oct
    Link to this post

    Hi,

    I need to display a navigation menu with a different image for each menu item, I don't want to create a custom widget for that because except for this image all the needed functionalities are presents in the out of the box navigation widget.

    Is there a way to access to the page custom fields inside the out of the box navigation widget?

    Thanks in advance for your help.

    David.

     

    Answered
  2. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    01 Nov in reply to David
    Link to this post

    Hi David, u can access page custom fields in this way (example of template for navigation widget for Feather)

    @model INavigationModel
    @using Prototype.Sitefinity.SitefinityControllers
    @using Telerik.Sitefinity.Frontend.Mvc.Helpers
    @using Telerik.Sitefinity.Frontend.Navigation.Mvc.Models;
    @using Telerik.Sitefinity.Modules.Libraries
    @using Telerik.Sitefinity.Pages.Model
    @using Telerik.Sitefinity.Web
    @foreach (var node in Model.Nodes)
    {
        PageSiteNode pageNode = node.OriginalSiteMapNode as PageSiteNode;
        var thumbnail = ((Telerik.Sitefinity.Libraries.Model.Image) pageNode.GetCustomFieldValue("Image"));
        <div>@node.Title
        <span>
        @if (thumbnail != null)
        {
            <img src="@thumbnail.ResolveThumbnailUrl(true)" alt="@thumbnail.AlternativeText">
        }
        </span>
        </div>
    }

     

    Please let me know if you need example for non-Feather widget

  3. David
    David avatar
    0 posts
    Registered:
    18 Sep 2016
    05 Nov in reply to Victor Leontyev
    Link to this post
    Thank you for your help Victor it works perfectly.
3 posts, 1 answered