1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Accessing page template's place holders

Accessing page template's place holders

6 posts, 1 answered
  1. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    29 Jun 2010
    Link to this post
    Can I access the ContentPlaceHolders of a template through the SiteFinity API?

    The problem I am trying to solve is that when I use the Staged page to get all the latest content, it seems to contain controls I added to the page using a previous template i.e. Create page, choose template A, add control, switch to template B, add new controls - access staged page and get controls from template A and B rather than only controls from template B (the current template).

    I would like to select only the controls whose ContainerID belongs to the current template.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    29 Jun 2010
    Link to this post
    Hello Chris,

    The code below will give  you access to the ContentPlaceHolder ( ContentPlaceHolders are declared in the master page, not inside ICms page)

    ContentPlaceHolder holder = this.Page.FindControl("MyHolder") as ContentPlaceHolder;
            if (holder != null)
            {
                
      
            }


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    29 Jun 2010
    Link to this post
    Is it not possible to get some kind of reference to the placeholders (or containers) using the API so I can do something along the lines of the following code...

    var controlsOnCurrentPage = stagedPage.Controls.Where(c => ContainerBelongsToTemplate(c.ContainerId, stagedPage))

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    29 Jun 2010
    Link to this post
    Hi Chris,

    You could try to get the container from the control

    // currentPage is ICmsPage
    IList<Telerik.Cms.ICmsWebControl> pageControls = currentPage.Staged.Controls;
    foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
    {
     if (webCtrl.ContainerID == "MyContainerId")
     {
        // do something   
     }
    }


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    30 Jun 2010
    Link to this post
    Yeah, this is what I'm currently doing, I didn't know if there was a better than checking against a static set of container IDs. Thanks Ivan.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    30 Jun 2010
    Link to this post
    Hello Chris,

    Using our API this is the way that you can use to access the holder. Otherwise you should use the methods suggested in my first reply.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 1 answered