Developer forum

Forum » Development » How to make a global loop in a Standard.Page.OnGlobalTags subscriber

How to make a global loop in a Standard.Page.OnGlobalTags subscriber

Jesper Laustsen
Reply
Can anyone provide an example of how to make a global loop in the OnGlobalTags notification?

/Jesper

Replies

 
Vladimir
Reply
Hi Jesper!
Sorry... that you mean by global loop?

[Subscribe(Dynamicweb.Notifications.Standard.Page.OnGlobalTags)]
public class GlobalTags : NotificationSubscriber
{
    public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
    {
        var parameters = args as Dynamicweb.Notifications.Standard.Page.PageviewNotificationArgs;
        if (parameters == null) return;

        if (parameters.Template.LoopExists("superGlobalLoop"){
            Templatev2.Template t = parameters.Template.GetLoop("superGlobalLoop");
            foreach( string item in itemsCollections){
            RendererMyItem( t, item );
            t.CommitLoop();
            }
        }
    }
}


 
Jesper Laustsen
Reply

Sorry for the late reply, - at the time, I found another way of solving it, but now have the need for a solution again. My approach to the global loop is exactly the same as yours, however it does not show with DwTemplateTags(inserted on master page), and it does not render in my Content module:

[Subscribe(Dynamicweb.Notifications.Standard.Page.OnGlobalTags)]
    public class NotificationOnGlobalTagsFooterBrands : NotificationSubscriber
    {
        public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
        {
            Dynamicweb.Notifications.Standard.Page.PageviewNotificationArgs a = (Dynamicweb.Notifications.Standard.Page.PageviewNotificationArgs)args;

            Brand BrandClass = new Brand();
            List<Brand> Brands = BrandClass.GetBrands();
            a.Template.SetTag("Global:NIQ:Test", "Global test");

            if (a.Template.LoopExists("Global:NIQ:Brandsloop"))
            {
                Dynamicweb.Templatev2.Template BrandsLoop = a.Template.GetLoop("Global:NIQ:BrandsLoop");
                foreach (Brand b in Brands)
                {
                    BrandsLoop.SetTag("Global:NIQ:BrandsLoop.Brand", b.Brand);
                    BrandsLoop.SetTag("Global:NIQ:BrandsLoop.Description", b.Description);
                    BrandsLoop.SetTag("Global:NIQ:BrandsLoop.Sort", b.Sort);
                    BrandsLoop.SetTag("Global:NIQ:BrandsLoop.Classification", b.Classification);
                    BrandsLoop.SetTag("Global:NIQ:BrandsLoop.ShowInFooter", b.Showinfooter);
                    BrandsLoop.SetTag("Global:NIQ:BrandsLoop.Logolink", b.Logolink);

                    BrandsLoop.CommitLoop();
                }
            }
        }
    }

 

You must be logged in to post in the forum