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?
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
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"
/>
Sabrie,
Thank you for your reply. I reached out to Mariush on Friday and he was able to point me to a solution yesterday.
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