Adding image to BlogPostList

Posted by Community Admin on 04-Aug-2018 21:56

Adding image to BlogPostList

All Replies

Posted by Community Admin on 06-Oct-2015 00:00

Hi,

 I'm using SF 8.1.5810.0 with Feather and am running in pure MVC mode.  I've added a 'custom field for posts' called "FeaturedImage" as type "Related Media".

 

I've copied the List.BlogPostList.cshtml and created a custom List.CustomBlogPostList.cshtml.  I'm having trouble getting the image to show.  Here is my code:

@foreach (var item in Model.Items)
   
        var navigateUrl = HyperLinkHelpers.GetDetailPageUrl(item, ViewBag.DetailsPageId, ViewBag.OpenInSamePage);

        <div class="row">
            <div class="col-sm-12">
                <div class="article featured" @Html.InlineEditingAttributes(Model.ProviderName, Model.ContentType.FullName, (Guid) item.Fields.Id)>

                    <img src="@item.Fields.FeaturedImage.MediaUrl" alt="@item.Fields.FeaturedImage.Title" />

                    <a class=" article__title" @Html.InlineEditingFieldAttributes("Title", "ShortText") href="@navigateUrl">@item.Fields.Title</a>

                    <p class="article__excerpt" @Html.InlineEditingFieldAttributes("Summary", "ShortText")>
                        <strong>@item.GetDateTime("PublicationDate", "MMM d, yyyy") - </strong>@Html.Raw(item.Fields.Summary) [...]
                    </p>
                </div>
            </div>
        </div>

   

 When I run this, I get this error message:

Exception occured while executing the controller. Check error logs for details.

Any suggestions?

Posted by Community Admin on 13-Oct-2015 00:00

Hello Dana,

You can try to add the following code in the custom BlogPostsList template:

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

I hope this helps.

Regards,
Svetoslav Manchev
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
 

Posted by Community Admin on 19-Oct-2015 00:00

That worked! thanks.

This thread is closed