Pulling Nested Content from a child node and displaying on homepage
I have set up a "nested content" component on my "Testimonials" page which is a few levels deep within my site. my stucture is:
Home, About > Why Us > Testimonials
I would like to display these testimonials on my homepage. The only difference is I will want to display the top 4 testimonials on the homepage within a carousel.
Is this possible to get these values from a child element and display on my homepage? Completely new to Umbraco and no idea where to start.
Here is my code currently on my testimonials page.
Thanks for the help with this Marcio. I had to adjust how you were getting the page to pull from. I thought id rather get the page by id rather than path name incase the name of the page was changed.
This is my working code:
@{
var testimonials = Umbraco.TypedContent(1078).GetPropertyValue<IEnumerable<IPublishedContent>>("clientTestimonials").Take(4);
foreach (var item in testimonials)
{
<div class="item">
<p>@Umbraco.Field(item, "clientTestimonial")</p>
<p class="text-right">@item.GetPropertyValue("clientName")</p>
</div>
}
}
Pulling Nested Content from a child node and displaying on homepage
I have set up a "nested content" component on my "Testimonials" page which is a few levels deep within my site. my stucture is:
Home, About > Why Us > Testimonials
I would like to display these testimonials on my homepage. The only difference is I will want to display the top 4 testimonials on the homepage within a carousel.
Is this possible to get these values from a child element and display on my homepage? Completely new to Umbraco and no idea where to start.
Here is my code currently on my testimonials page.
Any help/advice on the above would be much appreciated .
try this:
Thanks for the help with this Marcio. I had to adjust how you were getting the page to pull from. I thought id rather get the page by id rather than path name incase the name of the page was changed.
This is my working code:
Hi David, good that you found a solution. I have a second solution for you that will not fail if the page id changes.
I'm only demonstrating this for those who will find this useful, use it if you want to.
@{
}
Happy coding!
-B.
It was pointed out to me that .Descendants might be a bit too excessive if you have a big tree with a lot of nodes.
If you know its under your root node, then use .Children instead.
-B.
is working on a reply...