More in this section

Forums / General Discussions / Programmatically getting the widgets on a page

Programmatically getting the widgets on a page

2 posts, 0 answered
  1. Chris Bryant
    Chris Bryant avatar
    33 posts
    Registered:
    07 Jul 2009
    18 Apr 2011
    Link to this post
    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.
  2. reAnimated
    reAnimated avatar
    11 posts
    Registered:
    27 Apr 2009
    18 Apr 2011
    Link to this post
    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;
        }       
    }
2 posts, 0 answered