Hi - I have found this documentation on showing item relations using razor, and have tried it on my project - but can´t get it to work. Not shure if I have understood it correctly, and if what I try to achieve is possible.
What i have is a relation between two items (Company and Porjects). When you create a project, there is an item relation to one or more companys in an item relation field.
The name of the Company ItemType is Company
The name of the Project ItemType is Project
On the project ItemType, there is a item relations field called CompanyRelation where the company or companies that are responsible for the project are selected (For now there is just one company responsible for each project).
- Now, what I want to achieve is - in a list where I show all the companies using an item publisher, I want to show the related projects for each company.
Is this possible? If yes, Anyone have a suggestion on what the Razor code would loook like?
Thank you very mutch for your help.
regards, Hans
@{
// Get items of type News where News.ItemRelation includes this item (of type News with id GetString("Item.Id"))
var items = new Dynamicweb.Content.Items.Queries.Repository("News").SelectByReference("NewsRelation", "News", GetString("Item.Id"), null, false, false);
foreach (var item in items) {
<
pre
><
a
href
=
"Default.aspx?Id=@item.Page.ID"
>@item["Headline"]</
a
></
pre
>
}
}
@{
// Get items of type News where News.ItemRelation includes this item (of type News with id GetString("Item.Id"))
var items = new Dynamicweb.Content.Items.Queries.Repository("News").SelectByReference("NewsRelation", "News", GetString("Item.Id"), null, false, false);
foreach (var item in items) {
<
pre
><
a
href
=
"Default.aspx?Id=@item.Page.ID"
>@item["Headline"]</
a
></
pre
>
}
}