Developer forum

Forum » CMS - Standard features » items relation linking backwards

items relation linking backwards

Hans Ravnsfjall
Reply

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>
  }
}
- See more at: http://developer.dynamicweb.com/documentation/for-designers/how-to-relate-items-using-razor.aspx#sthash.m7hBmJSz.dpuf
@{
// 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>
  }
}
- See more at: http://developer.dynamicweb.com/documentation/for-designers/how-to-relate-items-using-razor.aspx#sthash.m7hBmJSz.dpuf

Replies

 
Nicolai Høeg Pedersen
 
Hans Ravnsfjall
Reply

This is unfortunately too steap a mountain to climb for my limited knowledge, so in hope of someone showing me some christmass mercy, I am attaching the two xml files and i will publish the template i use here.

* ItemType_Verkaetlanir.xml is for project data
* ItemType_Fyritoka.xm is for Company data

In my list where I show all companies. I want to show related sublists - where the projects that the given comapny is responisble for is listed.

But i can´t get the backward linking to work.

 

The template without the backward linking is like this

___________________________________________

<h1 style="font-size:30px;">FYRITØKUR</h1>

 

        @foreach (LoopItem i in GetLoop("ItemPublisher:Items.List")){
       <text>

<div class="col-md-12" style="background-color:#fff; margin-bottom:15px; padding-top:10px; padding-bottom:5px;">
  <div class="col-md-3">
    <img src='@i.GetValue("ItemPublisher:Item.Bumerki.Value")' />  
  </div>
 
  <div class="col-md-6">
    <h1><a style="color:#008196" onclick="location.href = '@i.GetValue("ItemPublisher:Item.DetailsUrl")';">@i.GetValue("ItemPublisher:Item.Navn_Fyritoku.Value")</a></h1>
    <a style="color:#e68c11;" href='http://@i.GetValue("ItemPublisher:Item.Heimasida_fyritoku")' target="_blank">@i.GetValue("ItemPublisher:Item.Heimasida_fyritoku")</a>
  </div>
 

 
  <div class="col-md-3">
    <p style="text-align:right">@i.GetValue("ItemPublisher:Item.Byur_Bygd.Value")</p>
  </div>
 
</div>

###### Here I want to show a list of the Projects (Verkaeltanir) that the company (Fyritoka) is responsible for ######

            </text>

 

      
        }

 

____________________________________

 

Hope someone can help? Would really appreciate it
 

 

 

 

 

You must be logged in to post in the forum