Developer forum

Forum » Templates » Show Item Types in another Page

Show Item Types in another Page

Kevin O''Driscoll
Reply

Hi can any one tell me why this dosnt work in a Razor template?

@using System.Collections.Generic;
@using Dynamicweb.Content.Items;
@using Dynamicweb.Content.Items.Queries;

@{
    IEnumerable<Item> allItems = null;
    ItemManager.Initialize();
    using (var repository = ItemManager.Storage.Open("Category"))
    {
        var query = new Query();
        query.Fields = new List<string>() { "Sort", "Id", "Category_Name", "Category_Description", "Category_Image", "Category_Page" };
        query.OrderBy = new OrderByCollection();
        query.OrderBy.Add(new OrderBy("Category_Name", OrderByDirection.Ascending));
        query.Offset = 0;
        query.Amount = 1000;

        allItems = repository.SelectByPageId(227, query);
    }
}

@if (allItems != null)
{
    <p>allItems not null!</p>
    <ol>
        @foreach (var item in allItems)
        {
            <li>@item["Category_Name"] (sort: @item["Sort"]) NEW STUFF</li>
        }
    </ol>
}

PageID 227 has 7 ItemTypes of type Category and is published

I also tried the following with the noted results:

            IEnumerable<ItemEntry> f = ItemManager.Storage.GetByPageId("Category", 227); // returns null
            ItemCollection fa = ItemManager.Storage.GetByPageId("Category", 227); // returns null
            IEnumerable<Item> fb = ItemManager.Storage.GetByPageId("Category", 227); // returns null
            Item i = ItemManager.Storage.GetById("Category", "264");  // Gets the Item type by its Id returns one Item Type
            ItemCollection cd = ItemManager.Storage.GetByParagraphId("Category", 23003);// Gets the item type by its containing paragraph

Enterprise version 8.3.1.18


Replies

 
Nicolai Høeg Pedersen
Reply

Can I ask why you are not using the item publisher?

 
Kevin O''Driscoll
Reply

Hi Nicoli - The Item Publisher does not seem to want to give a very important bit of Data - the Id.

The question is above -  why this dosnt work in a Razor template?

 
Mikkel Ricky
Reply

The item id has been available i the tag ItemPublisher:Item.Field.Id since Dynamicweb 8.4 (cf. http://templates.dynamicweb-cms.com/TemplateTags/Dynamicweb-template-tags/Module-tags/Item-publisher/List/Loops/ItemPublisherItems-List.aspx).

In your Razor code you should use SelectByParentPageId rather than SelectByPageId, but using the item publisher is the recommended way to do it.

Best regards,
Mikkel

 

 

You must be logged in to post in the forum