1
votes

Im new to umbraco. im trying to display certain section of one template inside another template. for e.g.

1) i have Product page, which lists all the products and few description about them. 2) now i want to show this content to my home page also. i dont want to copy and paste code from product page to home page..as this would require me to do the same if some changes come on product page.

Also, Product page contains child nodes, which automatically displayed by Macro. i just want to display Product page contents to my home page.

Thanks in advance.

1

1 Answers

0
votes

You simply need to add a new macro that will display the product page contents you need and then add it into the homepage template.

Doing it as a razor scripting file would be something like (where 1111 is your product page node id). If you use ucomponents you could use uQuery.getNodeByUrl or some other nicer helper method, but this code should work out of the box:

var productPage = @Model.NodeById(1111);            
<div>
<a href="@productPage.Url">
<h4>
@productPage.copyHeadline
</h4>
</a>
@if (!string.IsNullOrEmpty (@productPage.copyBlurb.ToString ()))
{
@Html.Raw(@productPage.copyBlurb.ToString().Substring(0, 200) + "...");
}
</div>