Developer forum

Forum » CMS - Standard features » Website Item list loop

Website Item list loop

Nuno Aguiar
Reply

Hi,

 

We can easilly access an item list loop within the master and layout template, but within another template we cannot (example, product template).

 

How can we access that data in a loop within Pageview.Area.Item?

Right now we we have to do this:

string str_social = Pageview.Area.Item["Social"] != null ? Pageview.Area.Item["Social"].ToString() : "";
foreach (var socialID in str_social.Split(','))
    {
        var item = Dynamicweb.Content.Items.ItemManager.Storage.GetById("Social", socialID.ToString());
        if (item != null)
        {
            // do something
        }
    }

 

The problem is that this will make a DB call for each loop interaction and if we have multiple item lists, the problem grows.

 

Best Regards,

Nuno Aguiar


Replies

 
Viktor
Reply

Greetings.

We really appreciate your appeal and will try to do anything to help you. 

I think this is what you looking for:

http://templates.dynamicweb.com/TemplateTags/Dynamicweb-template-tags/Page-tags/Page/Item-Area-FieldSystemName.aspx

http://templates.dynamicweb.com/TemplateTags/Dynamicweb-template-tags/Page-tags/Page/Item-Page-FieldSystemName.aspx

There is no fields or groups loop support, but you can refer to area item through this:

@GetValue("Item.Area.SystemName"), @GetValue("Item.Area.Name"), @GetValue("Item.Area.[FIeldSystemName].Name"), @GetValue("Item.Area.[FIeldSystemName].Value"), @GetValue("Item.Area.[FIeldSystemName].Type"), @GetValue("Item.Area.[FIeldSystemName].IsRequired")

add  <!--@DwTemplateTags--> to your template or add request parameter at url (?dwtemplatetags=true) and you can see available tags for your area/page property item.

 

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

Hi Viktor,

 

You did not understand what I wrote. You are telling me how to use tags in a Page and/or Master template. I know how to do that and do loops.
"We can easilly access an item list loop within the master and layout template"

 

What I am trying to do a better way to access Area loop tags in a module template. If I do something like Pageview.Area.Item["Social"].ToString() I get back a csv with all of the item ID's and then I need to query the database for every one. This is not a good idea. Either the pageview object should have those values or we should easilly call them out once, instead of having to a call to Dynamicweb.Content.Items.ItemManager.Storage.GetById() for everyone.

 

Best Regards,

Nuno

 
Viktor
Reply

Hi Nuno, 
i want to clarify that i used those tags below directly at the product.html - i.e. product details template and they show me data from Area Item, is that what you wanted for?


<!--@Item.Area.SystemName-->
<!--@Item.Area.Testfield-->
<!--@Item.Area.Testfield.IsRequired-->
<!--@Item.Area.Testfield.Name-->
<!--@Item.Area.Testfield.SystemName-->
<!--@Item.Area.Testfield.Type-->
<!--@Item.Area.Testfield.Value-->


And looks like i found a bug - that razor cannot render those tags inside module - it got his own scope without needed tags =\

I've created TFS item # 17435 to fix this.

If you think i miss understand you even now let me know and i'll try to help you

 

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

Hi Viktor,

 

Maybe it is related, but I think you are not getting the issue. The problem is getting the Item lists values. Check the attachments

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Nuno

The latest 8.6.1 release has a "Cache item" feature (TFS#17266). On the item type, set it to cacheable on your social icons, and use your code. Then the social media items will be loaded from cache each time and get rid of the DB call.

BR Nicolai

Votes for this answer: 1
 
Nuno Aguiar
Reply

Hi Nicolai,

 

Great. Just saw that in 8.6.1.8 bug fixes list.

 

Thanks,

Nuno Aguiar

 

You must be logged in to post in the forum