Developer forum

Forum » Templates » Item template - itemlist and itemrelationlist problems

Item template - itemlist and itemrelationlist problems

René Poulsen
Reply

Hi,

I have to create a contactpage where I have 3 levels (contactarea, office/department, employees) and some rules for the employees, so that specific employees is only shown when an office is shown under a specific business area.

The structure in DW is:

  • Contactarea item is created as paragraphs. On the item I can choose which offices to show via. an itemrelationlist where I can point to office pages.
  • Office item is created as pages. Employyes is created in an itemlist on theese pages.

On the employee I've also created an itemrelationslist where I can point to contactarea paragraphs, so I'll be able to determine wether or not to show the employee under the specific business area. By doing it like this I think I should be able to do this:

  • Business Area 1 (item id = 4)
    • Office A
      • Employee 1
    • Office B
      • Employee 2
  • Business Area 2 (item id = 5)
    • Office A
      • Employee 3
    • Office B
      • Employee 4

The problem is that (even though I've created an itemrelationslist on the employee pointing to the contactarea) I can't seem to relate the employee to the contactarea.

In the template for the contactarea paragraph I can get the item id for the contact area. Then i loop through the offices and employyes inside like this

 

foreach (var office in GetLoop("Item.Offices")) {

    <h3>@office.GetString("Item.Offices.Name")</h3>

    foreach (var employee in office.GetLoop("Item.Offices.Employees")) {

        <div>@employee.GetString("Item.Departments.Employees.Areas")</div> /* This is where I would expect to get the value "4" or "5" when pointing to Business Area 1 or Business Area 2, as they have "4" and "5" as item id. Instead I get a new value, each time I delete and create the relation again. This means that I can't really tell if I'm to show the employee or not - because I can't relate the employee to the area, when there's no IDs to compare */

    }

}

Please let me know if you don't understand the problem - I'll try to explain it better or send some screenshots from database/paragraph/pages :-)


Replies

 
Nicolai Høeg Pedersen
Reply

Hi René

Some screen shots of the item types and the input screens would be nice.

What happens if you ask for a loop instead of @employee.GetString("Item.Departments.Employees.Areas")

 
René Poulsen
Reply

Hi Nicolai,

If I output @employee.TemplateTags there's no loop for the areas. That was my initial idea, but when it's not there I can't use it.

I've attached a lot of screenshots. One of the database where you can see the values in the contactarea item i'm relating an employee to - and the value in the "area" item on the employee.

There's also some from the paragraphs and pages + of the 3 items in MC.

 
René Poulsen
Reply

Bump

 
Vladimir
Reply

Hi René,

>The problem is that (even though I've created an itemrelationslist on the employee pointing to the contactarea) I can't seem to relate the employee to the contactarea.

Related list fields contain id of a list (it is a key of [ItemList] table - which has relation to item ids in [ItemListRelation] table)

The other problem is that a loop for Item.Departments.Employees.Areas is absent - there is a limitation currently that DW renders only 3 level of hierarchy - due to performance reason/ circular refferences avoiding (though probably it will better to make configurable)

but this is 4th level ( area(1) -> department(2) ->employe(3)-> area(4))


Probably the solution is could be to use "raw" items rendering:
 @{
    var list = Dynamicweb.Content.Items.ItemList.GetItemListById(employee.GetInteger("Item.Departments.Employees.Areas"));
}
<ul>
    @foreach (var itemEntry in list.Relations) {
        var item = new Dynamicweb.Content.Items.Item(itemEntry);
        <li>@item["Id"] - @item["Name"]</li>
    }
</ul>

Best regards,

Vladimir

 

You must be logged in to post in the forum