display custom image field in custom template - General Discussions - General Discussions - Progress Community
 General Discussions

display custom image field in custom template

  • display custom image field in custom template
  • I am finding that nothing is straightforward in Sitefinity and that finding documentation that addresses issues I encounter is difficult.  

     I created a custom field for News items that is an Image type.  I have also created a custom template for displaying the news items.  However, as part of that template, I want to display the image.  How does one accomplish this?

  • Tim,

    See if this helps...  Its a video from YouTube.

    www.youtube.com/watch

     

    Craig

  • Craig,

     It seems I needed to include more info in my original post.  I am doing pure MVC pages.  My template was defined in Visual Studio.  If I display "item.Fields.NewsItemImage" in my template, "Telerik.Sitefinity.Frontend.Mvc.Models.ItemViewModel[]" is displayed on screen.  I simply do not know how to get from "Telerik.Sitefinity.Frontend.Mvc.Models.ItemViewModel[] " to being able to populate the src member of an img element.

    Any ideas?

  • Tim,

    Sorry I don't have much knowledge in the Sitefinity MVC realm.  Definitely an area where I plan to learn more about in the future.  Good luck.  :-)

     

    Craig

  • Sabrie,

     Thank you for your reply.  I reached out to Mariush on Friday and he was able to point me to a solution yesterday.

  • Hi Tim,

    Can you please try to use the following sample code for displaying the custom related image of news items in an MVC widget template:


    @foreach (var relatedItem in item.Fields.RelatedImagesFieldName)
      <img src="@relatedItem.Fields.MediaUrl" alt="@relatedItem.Fields.Title" />

    Please note to replace the RelatedImagesFieldName with the name of your custom related field.

    You may also refer to the following documentation article for more details on this:
    https://github.com/Sitefinity/feather/wiki/Add-related-data-to-News-widget

    Regards,
    Sabrie Nedzhip
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • could you please relay that solution here? When I read your initial post I almost thought that I had typed it. I am experiencing the exact same issue. It would be greatly appreciated.
  • I wish I could provide that to you.  I was evaluating Sitefinity for a project.  It ended up not being the product chosen.  I have since uninstalled Sitefinity from my PC.  Sorry I couldn't be more help. 
  • Thanks
  • Sabrie this solution worked fine but it's targeting the largest image, is there a call for one of the other sizes?

     

    Charles