Programmatically getting the widgets on a page

Posted by Community Admin on 03-Aug-2018 16:40

Programmatically getting the widgets on a page

All Replies

Posted by Community Admin on 18-Apr-2011 00:00

Is there a way to programmatically fetch the widgets on a particular page?  I haven't been able to find anything in the Fluent API for this.

I'm looking to programmatically build a subnav based on a parent page that is a grid of widgets.  Obtaining a simple list of Widgets by Page is all I need.

Thanks!
-Chris B.

Posted by Community Admin on 18-Apr-2011 00:00

You can see how to add/remove controls on a page using the Sitefinity API here. Also you can find the below code snippet in the news rotator sample control. This looks for pages containing a particular type of control:

private PageNode targetNewsPage;
 
protected PageNode TargetNewsPage
    get
    
        if (this.targetNewsPage == null)
        
            this.targetNewsPage = App.WorkWith().Pages()
                        .Where(p => p.Page != null &&
                                    p.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(NewsView).FullName)).Count() > 0)
                        .Get().FirstOrDefault();
 
         //it can still be null in case there is no page with a NewsView on it
 
        return this.targetNewsPage;
           

This thread is closed