Developer forum

Forum » Templates » Razor Get items (paragraph) from a item page

Razor Get items (paragraph) from a item page

António Ramos
Reply

Hi guys,

I'm tring to get with the API all the paragraph items from a item page, using the GetByParentPageId from the Items.Queries.StorageManager but the "Count" it always give me 0.

This method only retrive page items under that page or it should also retrieve paragraphs?

Anyone have another ideia to accomplish this situation?

Thank you in advance,

Best regards,

António Ramos

 

 


Replies

 
Viktor
Reply

Greetings.

I am not sure I am fully understand the result, which you are desired to get.

If you wanted to get count for all paragraph items at the page you can use something like that :

@{    var count = 0;
                  var paragraphs = Dynamicweb.Content.Paragraph.GetParagraphsByPageID(GetInteger("Global:Page.ID"));
                  foreach (Dynamicweb.Content.Paragraph p in paragraphs ){
                      if(!String.IsNullOrEmpty(p.ItemType)){
                          var items = Dynamicweb.Content.Items.ItemManager.Storage.GetByParagraphId(p.ItemType, p.ID);
                          count += items.Count();
                      }
                  }
              }
              Items Count : @count

Also you can get item inside paragraph template, but this probably always return only 1 item: 

   @{     var items = Dynamicweb.Content.Items.ItemManager.Storage.GetByParagraphId(GetString("Item.SystemName"), GetInteger("Global.ParagraphId"));
         var count = items.Count();
          }
      Items Count @count

If it doesn't solve your problem reply here, I'll try to find out another solution for it

Best regards,
Viktor Letavin
DynamicWEB Software A/S, Russian team
 
Viktor
Reply
 
Viktor
Reply
 
Viktor
Reply
 
Viktor
Reply

 

You must be logged in to post in the forum