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

4 posts, 1 answered
  1. David
    David avatar
    0 posts
    Registered:
    18 Sep 2016
    26 Oct 2016
    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 2016 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 2016 in reply to Victor Leontyev
    Link to this post
    Thank you for your help Victor it works perfectly.
  4. Enas
    Enas avatar
    0 posts
    Registered:
    25 Feb 2016
    19 Jan in reply to Victor Leontyev
    Link to this post

    I want to add a short text as a header for some nodes , I have added a custom field ( Header_Text) as a short text . but I am unable to use it within the MVC navigation control. please advise.

            

4 posts, 1 answered