Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Dears,
I have a Blog having properties, Title, Image, Blog content and etc.. I want to display all blog main page to navigate to respective blog pages
Here is the code
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.NewsList> @using ContentModels = Umbraco.Web.PublishedContentModels; @{ Layout = "Master.cshtml"; } @foreach (var page in CurrentPage.Children) { <div class="blogblk"> <a href="@page.Url"> <div class="blogimg"><img src="*@Iam stuck here to display the image url*"></div> <div class="blogdesc"> <h4>@page.bTitle</h4> <p>@page.bExcerpt</p> </div> </a> </div> }
I am getting all other properties, except Image URL. appreciate your advice, where i am going wrong
Thanks Aju
Would this do the trick?
<div class="blogblk"> <a href="@page.Url"> <div class="blogimg"> @{ var mediaGet1 = Model.Content.GetPropertyValue<IPublishedContent>("imageAlias"); if (mediaGet1 != null) { <img src="@mediaGet1.GetPropertyValue("umbracoFile")" /> } } </div> <div class="blogdesc"> <h4>@page.bTitle</h4> <p>@page.bExcerpt</p> </div> </a> </div>
Remember to replace "imageAlias"
Hello Bent,
Thanks for your reply, I am getting the following error
[NullReferenceException: Object reference not set to an instance of an object.] Umbraco.Web.PublishedContentExtensions.GetPropertyValue(IPublishedContent content, String alias) +4
And I am using Media Picker at backoffice
Thanks
What does your code look like now?
<div class="bloglist"> @foreach (var page in CurrentPage.Children) { <div class="blogblk"> <a href="@page.Url"> <div class="blogimg"> @{ var mUrl = Model.Content.GetPropertyValue<IPublishedContent>("bImage"); if (mUrl != null) { <img src="@mUrl.GetPropertyValue("umbracoFile")" /> } } </div> <div class="blogdesc"> <h4>@page.bTitle</h4> <p>@page.bExcerpt</p> </div> </a> </div> } </div>
@foreach (var page in Model.Content.Children.Where(x => x.IsVisible())) { <div class="blogblk"> <a href="@page.Url"> <div class="blogimg"> @{ var media = page.GetPropertyValue<IPublishedContent>("bImage"); if (media != null) { <img src="@media.Url" /> } } </div> <div class="blogdesc"> <h4>@page.GetPropertyValue("bTitle")</h4> <p>@page.GetPropertyValue("bExcerpt")</p> </div> </a> </div> }
Or try this
@foreach (var page in Model.Content.Children.Where(x => x.IsVisible())) { <div class="blogblk"> <a href="@page.Url"> <div class="blogimg"> @{ var mediaID = page.GetPropertyValue<string>("bImage"); var media = Umbraco.TypedMedia(mediaID); if (media != null) { <img src="@media.Url" /> } } </div> <div class="blogdesc"> <h4>@page.GetPropertyValue("bTitle")</h4> <p>@page.GetPropertyValue("bExcerpt")</p> </div> </a> </div> }
Hello Garðar Þorsteinsson,
Very thanks for your reply and both snippets works great. Fantastic.
Thank you.
One more thing, After navigating to respective blog post , I want to give URL to come back to Blog Main Page, can u pls add that too
If you are meaning a link from the blog to the blog parent page then you could use this code on the blog page.
@Model.Content.Parent.Url
or if the page is not the first parent or could be on any level you could use this
@Model.Content.Ancestor("blogMainDocTypeAlias").Url
Thank you..
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Rendering a Single Image
Dears,
I have a Blog having properties, Title, Image, Blog content and etc.. I want to display all blog main page to navigate to respective blog pages
Here is the code
I am getting all other properties, except Image URL. appreciate your advice, where i am going wrong
Thanks Aju
Would this do the trick?
Remember to replace "imageAlias"
Hello Bent,
Thanks for your reply, I am getting the following error
[NullReferenceException: Object reference not set to an instance of an object.] Umbraco.Web.PublishedContentExtensions.GetPropertyValue(IPublishedContent content, String alias) +4
And I am using Media Picker at backoffice
Thanks
What does your code look like now?
Or try this
Hello Garðar Þorsteinsson,
Very thanks for your reply and both snippets works great. Fantastic.
Thank you.
One more thing, After navigating to respective blog post , I want to give URL to come back to Blog Main Page, can u pls add that too
If you are meaning a link from the blog to the blog parent page then you could use this code on the blog page.
or if the page is not the first parent or could be on any level you could use this
Thank you..
is working on a reply...