Developer forum

Forum » Templates » Item publisher, List items of already ItemPublisher:Items.List listed item

Item publisher, List items of already ItemPublisher:Items.List listed item

Dmitrij Jazel
Reply

Hej guys,

I have a 3 level structure of Item pages in my site navigation

Every Level page is it's own Item type. 1) News 2) Group 3) Article

  • News
    • News_Group1
      • Article1
      • Article2
      • Article3
    • News_Group2
      • Article1
      • Article2

When I am at News page, I want to have a list of all News_Groups with help of Item publisher

I am trying to achieve something like this:

@{
        if(itemsAny){
            foreach (LoopItem i in GetLoop("ItemPublisher:Items.List"))
            {
                var Title = i.GetValue("ItemPublisher:Item.Title");
                
                <h3>@Title</h3>
                <div>
                    @foreach (LoopItem i2 in i.GetLoop("ItemPublisher:Items.List"))
                    {
                        <span> <<<--- I need my Article.Title here  --->>> </span>
                    }                                        
                </div>        
        
                <div>@i.TemplateTags()</div>
            }
        }
    }

My question is, while I am listing all groups, can I somehow access all articles (children of Group)?

In module settings I am including all clind items http://screencast.com/t/aM0m0jWhn32

 

/Dmitrij


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Dmitrij

Sub items of other types than the one you are publishing is not included in the item publisher.

When you have an item that is a page, you have its page id.

Then you can do something like this:

var Dynamicweb.Frontend.Page p = Dynamicweb.Frontend.Page.Findpage(ID);
if (Convert.ToBoolean(p.get_Value("PageHasChildren")) == true) {
	tmpPageChilds = p.get_Value("pagechilds");
	if ((tmpPageChilds != null)) {
		if (tmpPageChilds.GetType.ToString != "System.String") {
			PageChilds = (ArrayList)tmpPageChilds;
			foreach (int intChildPageID in PageChilds) {
				Dynamicweb.Frontend.Page.Findpage(intChildPageID).Item.Something			}
		}
	}
}
 
Mikkel Ricky
Reply
This post has been marked as an answer

You should be able to do this using an item publisher directly in your template, i.e. by using @RenderItemList(…) inside your loop:

foreach (…) {
  …
  <h3>@Title</h3>
  @RenderItemList(new {
    ItemType = "Article",
    …
  })
}

See http://templates.dynamicweb.com/TemplateTags/Dynamicweb-template-tags/Module-tags/Item-publisher/Item-Render.aspx for details on the parameters you can use in RenderItemList and see http://developer.dynamicweb.com/releases/dynamicweb-8-4-1.aspx#item14614 for examples on use.

Best regards,
Mikkel

Votes for this answer: 1
 
Jens Mouritzen
Jens Mouritzen
Reply

Trying to do the same here.
I have used the code in the examples in the above links. Here is the code that is wrote:

The template file:

    <div class="col-md-3">
      @RenderItemList(new {ItemType = "Cases",ListSourceType = "Page",ListSourceArea = 18,ItemFieldsList = "*",ListTemplate = "ItemPublisher/List/List.cshtml",ListPageSize = 100,ListOrderBy = "StartTime"})
    </div>

List.cshtml:

​<div class="cases items">
  @foreach(LoopItem i in GetLoop("ItemPublisher:Items.List")){
    <p>@i.GetString("ItemPublisher:Item.Title")</p>
  }
</div>

 

 

 

You must be logged in to post in the forum