Razor macro - how do I display a property alias in a list?
Hi. New to Umbraco, and Razor, and have read lots of docs and watched videos. I am trying to display a list of items in another page. I am writing my first Razor scripted macro, which I want to insert in a template for the new page.
This is what I have and this displays the name, and links to the item page. This works OK:
On my top level item doc. type I have a property alias called "widgetmodelDescription" - I would like to display this description under the 'item.name' above. I have tried several things but failed. Can anyone help?
In addition, under each of these top level items, I also want to show the names and descriptions of their child items, that are associated with each top level item. Example:
Notice that you have to fill in your own "childWidgetDocumentTypeAlias" since I don't know what that is. Also be sure to be very careful about the casing: for example, widgetmodelDescription and widgetModelDescription are NOT the same thing!
Razor macro - how do I display a property alias in a list?
Hi. New to Umbraco, and Razor, and have read lots of docs and watched videos. I am trying to display a list of items in another page. I am writing my first Razor scripted macro, which I want to insert in a template for the new page.
This is what I have and this displays the name, and links to the item page. This works OK:
@inherits umbraco.MacroEngines.DynamicNodeContext
@foreach (var item in Model.Children.Where("umbracoNaviHide != true").OrderBy("UpdateDate"))
{
<h3>
<a href="@item.Url">@item.Name</a>
</h3>
}
On my top level item doc. type I have a property alias called "widgetmodelDescription" - I would like to display this description under the 'item.name' above. I have tried several things but failed. Can anyone help?
In addition, under each of these top level items, I also want to show the names and descriptions of their child items, that are associated with each top level item. Example:
Item 1 'name' + 'description'
Item 2 'name' + 'description'
Thanks in advance.
Hi Kevin,
To display a property value in Razor, the Model or item is a dynamic object that lets you just read it like a regular property.
For example, you could try the following:
Notice that you have to fill in your own "childWidgetDocumentTypeAlias" since I don't know what that is. Also be sure to be very careful about the casing: for example, widgetmodelDescription and widgetModelDescription are NOT the same thing!
Best of luck to you!
Thanks Funka. I will try that :)
is working on a reply...