1

In my Content section I have a property editor (Archetype) that allows to set content for the site independently from the content tree. It looks like this:

enter image description here

I need to display only the sub categories from one category based on what page I'm currently on. What I have now is:

var catItems = Umbraco.Content(1123).categoryItem; //get the Set Content property editor from Content Section

foreach (var item in catItems)
{
    foreach (var sub in item.GetValue<ArchetypeModel>("subCatItem"))
    {
        <div class="tbl_dt">
            <p class="offerName">@sub.GetValue("offerName")</p>
            <p class="departurePort">@sub.GetValue("departurePort")</p>
        </div>
    }

}  

This is displaying all the sub category items from all categories. It should display only the sub categories based on current page. How can I make the connection between current page and the sub category item? Or it is best to stick with the property editor in the content tree pages?

alex
  • 1,300
  • 1
  • 29
  • 64
  • What is the type of `catItems`? Does it have a property that maps to the associated Page (should be an IPublishedContent). You can then use that property to check if the `item` is associated with your current page. – Philip Pittle Sep 03 '14 at 08:22
  • actually the type of `catItems` is `DynamicPublishedContent`. So I should add a content picker to it and map it to a content page? If so how would I check if the item is associated with current page? – alex Sep 03 '14 at 10:11

1 Answers1

0

The issue is not the code, but rather the structure of your Content Tree. You have nothing to Associate the Category/Offer to the page you want to display it on.

In order to create an the Association between ContentPage & Category/Offer DocType, you could try one of the following:

  1. Keep the Category/Offers as they are, independent of the content tree (i.e. Pool of Categories/Offers etc.) Then put a MNTP picker (multi-node tree picker) on the DocType that you want to create the Association between (i.e. 'ProductPage').

Each Page where you want to display the Category/Offer(s) you would need to call the MNTP Picker Property to get the NodeId of that specific Category/Offer for the current page.

Example:

var catNodeId = @CurrentPage.pickerPropertyAliasHere; //this will give us the NodeId of that specific offer selected for the current page, may need to refactor your code to handle parsing etc.

var catItems = @Umbraco.Content(catNodeId).categoryItem; //Get Categories/Offers from the Offer picked for the current page.

foreach (var item in catItems)
{
    foreach (var sub in item.GetValue<ArchetypeModel>("subCatItem"))
    {
        <div class="tbl_dt">
            <p class="offerName">@sub.GetValue("offerName")</p>
            <p class="departurePort">@sub.GetValue("departurePort")</p>
        </div>
    }

}
  1. Put your ArcheType property editor on the DocType you want to Associate with. Then simply call the property for that page and loop over the items again (see example below).

Example:

var catItems = @CurrentPage.categoryItem; //Get Categories/Offers for the current page

foreach (var item in catItems)
{
    foreach (var sub in item.GetValue<ArchetypeModel>("subCatItem"))
    {
        <div class="tbl_dt">
            <p class="offerName">@sub.GetValue("offerName")</p>
            <p class="departurePort">@sub.GetValue("departurePort")</p>
        </div>
    }

}  

Good Luck C

Craig Mayers
  • 185
  • 2
  • 9