I have a list of blog posts in a blog post repository that I want to display on the front page. What is the razor syntax to do that?
I thought one of these three code snippets would work, but not having any joy. Please help:
var blogPosts = CurrentPage.Site().Children("BlogPostRepository");
var blogPosts = CurrentPage.Site().Children("BlogPostRepository").Children("BlogPost");
var blogPosts = CurrentPage.Site().Children("BlogPostRepository")[0].Children("BlogPost");
If you are using the query builder in Umbraco 7.2.2 then you can use this Razor to display blogposts on the frontpage. You can find the query builder here.
@{ var selection = CurrentPage.Site().FirstChild("BlogPostRepository").Children("BlogPost").Where("Visible"); } <ul> @foreach(var item in selection){ <li> <a href="@item.Url">@item.Name</a> </li> } </ul>
Home page BlogPostRepository
Hello.
I'm using Umbraco 7.2.2
I have a list of blog posts in a blog post repository that I want to display on the front page. What is the razor syntax to do that?
I thought one of these three code snippets would work, but not having any joy. Please help:
Any help would be most welcome.
Leon
Hi Leon,
Try to use Descendants instead of Children, like that :
Thanks
Hi Leon
You can do it like this
I think you can also benefit from reading this cheat sheet of available methods etc. https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets
Hope this helps.
/Jan
Hi Leon,
If you are using the query builder in Umbraco 7.2.2 then you can use this Razor to display blogposts on the frontpage. You can find the query builder here.
Hope this helps,
/Dennis
is working on a reply...