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

Forums / Designing with Sitefinity / Define controls in placeholders in the tamplates

Define controls in placeholders in the tamplates

16 posts, 0 answered
  1. iocat
    iocat avatar
    5 posts
    Registered:
    01 Dec 2008
    08 Dec 2008
    Link to this post
    Hi, please could you advise how I can define controls within the placeholders of the templates or master page so that users can edit their content at page level. 

    We have requirements for complex page layouts and need the controls to be already in place and configured when the user creates a page.

    If there is nothing in the CMS admin that can do this, does the API expose an event such as PageCreated that I can hook into and add the controls programatically via the API?


  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Dec 2008
    Link to this post
    Hello iocat,

    Thank you for using our services.

    You could hardcode the controls in the master pages and set the properties there. Thus, the users will not be able to edit the properties of this controls except the user has access to the code.

    <body> 
        <form id="form1" runat="server"
            <asp:ScriptManager ID="ScriptManager1" runat="server"
            </asp:ScriptManager> 
            <div id="wrapper"
            <div id="Header"
                <h1>My Organization</h1> 
                <div id="TopNavigation"
                    <asp:contentplaceholder id="TopMenu" runat="server"
                    <asp:SiteMapDataSource ID="SitemapDataSource1" ShowStartingNode="false" runat="server" /> 
                    <telerik:RadTreeView ID="radtreeview" DataSourceID="SitemapDataSource1" runat="server"></telerik:RadTreeView> 
                    </asp:contentplaceholder>             
                </div> 
            </div> 
            <div id="Main"><asp:contentplaceholder id="Content" runat="server"></asp:contentplaceholder></div
            <div id="SideBar"><asp:contentplaceholder id="SideBarContent" runat="server"></asp:contentplaceholder></div>     
            <div id="Footer">2006-2007 &copy; MyOrganization. All rights reserved </div> 
           </div> 
       </form> 
    </body> 

    I hope this helps.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. iocat
    iocat avatar
    5 posts
    Registered:
    01 Dec 2008
    09 Dec 2008
    Link to this post
    Hi Ivan

    Many thanks for your reply. 

    I am wanting to define the sitefinity controls in the master page or template as you describe above and set basic properties, however this does not seem to allow the user to set the content for these controls when the page is created from the template or when a page is edited.

    For example I have a requirement for templates that have a large number of generic content and image controls, link lists etc already defined in the template but without content. 

    The user then creates a page and needs to be able to set the content for these controls in the same way they would if they dragged a control from the toolbox into a content placeholder on the page.

    I was initially looking for a way to place the controls in the template using the  template editor of the admin site and set some kind of property to allow their content to be set at page level.  However controls added to the site template only seem to be editable at template level - when pages are created from these templates, their content can not be set.

    Many Thanks

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Dec 2008
    Link to this post
    Hello iocat,

    thank you for getting back to me.

    You can try using BrowsableAttribute Class - Specifies whether a property/event should be displayed in a properties window. Setting Browsable attribute to false will allow you to enter content.

    Example:

    [Browsable(true)] // boolean value true or false
    [Category("MyCategory")] 
     public int MyProperty 
      { 
          get { return MyProperty; } 
          set { MyProperty = value; } 
      } 

    I hope this helps.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. iocat
    iocat avatar
    5 posts
    Registered:
    01 Dec 2008
    09 Dec 2008
    Link to this post
    Hi

    Thanks for your reply.

    Dont quite understand though - its the out of the box page controls (text editor, Image control etc) that I want to define either in the master page or template then allow the user to edit the controls content at page level.

    Please could you elaborate on how I could use the Browsable attribute to acheive this.

    Many thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Dec 2008
    Link to this post
    Hi iocat,

    Here is the link to MSDN where you can gather more information about BrowsableAttribute Class.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. iocat
    iocat avatar
    5 posts
    Registered:
    01 Dec 2008
    10 Dec 2008
    Link to this post
    Hi, Sorry to labour the point but I dont see how the Browsable attribute in any way relates to the problem I am having.  I think you my be missunderstanding the problem I'm having or perhaps I am not explaining it clearly enough.

    I simply want the template to act as a template - to be able to define controls (text, images etc) that the user can edit at page level when they create or edit a page - in a similar manner to the templates in other CMS products such as MOSS SharePoint 2007.

    I realy want to reccomend Sitefinity to my client, however this one issue is the only outstanding point preventing me from doing so.

    Many Thanks
  8. Jonathan
    Jonathan avatar
    13 posts
    Registered:
    16 Jun 2012
    11 Dec 2008
    Link to this post
    I completely see what you are saying but don't know how to do it either.

    Let me see if I can explain it for them.

    We need to be able to setup a template page that already contains the controls placed on the content areas so when the user goes to edit the page they don't have to drag 15 controls to edit the page, they can just hit the edit button and edit that section.

    We need it for a automotive listing page, so our users would just click add page and select automotive template, that template would already have an image gallery, and a couple content field. This way it saves them a ton of time.

    Is this possible? I know you could do it with the duplicate page button but doesn't make much sense.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Dec 2008
    Link to this post
    Hi Jonathan Marbutt,

    I am going to prepare a KB article regarding this implementation and send you a link here.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Dec 2008
    Link to this post
    Hi Jonathan Marbutt,

    Here is the link to the KB article http://www.sitefinity.com/support/knowledge-base/kb-article/b1154K-bbhb-b1154T-cma.aspx. The example shows how to get the template that the page should use, assign the template to the page, add the GenericContent control to "Content" placeholder.

    I hope this helps.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. Jonathan
    Jonathan avatar
    13 posts
    Registered:
    16 Jun 2012
    11 Dec 2008
    Link to this post
    Looks like you reference the wrong KB article, the correct one is here:
    http://www.sitefinity.com/support/knowledge-base/kb-article/b1154K-bcaa-b1154T-cgb.aspx
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Dec 2008
    Link to this post
    Hello Jonathan Marbutt,

    Thanks for the note. The correct URL is http://www.sitefinity.com/support/knowledge-base/kb-article/b1154K-bcaa-b1154T-cgb.aspx

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. iocat
    iocat avatar
    5 posts
    Registered:
    01 Dec 2008
    12 Dec 2008
    Link to this post
    Hi , Many thanks for your help, much appreciated. 

    Just one issue I'm having with adding the controls to the page via the APi is that I get the following error message if I try to add more than one control to a placeholder:

    IOdbClass must be joined to a transaction.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: IOdbClass must be joined to a transaction.


    I've tried adding multiple controls then calling SavePage method and have also tried calling SavePage method after adding each control but still get the error.

    Works fine when adding a single control.

    Any Ideas?

    Thanks

  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Dec 2008
    Link to this post
    Hi iocat,

    You need to get the page every time before adding a new control using this:

    page = cmsManager.GetPage(cmsPage.ID, true); 

    Then, you should save it:

    cmsManager.SavePage(page); 

    Here is the example where I am adding two additional controls:

     //add a second GenericContent control to "SideBarContent" placeholder with id genericContent2 
     page = cmsManager.GetPage(cmsPage.ID, true); 
     page.Staged.AddControl("SideBarContent"typeof(GenericContent), 0, "genericContent2"); 
     cmsManager.SavePage(page); 
     
     //add third GenericContent control to "SideBarContent" placeholder with id genericContent3 
     page = cmsManager.GetPage(cmsPage.ID, true); 
     page.Staged.AddControl("SideBarContent"typeof(GenericContent), 0, "genericContent3"); 
     cmsManager.SavePage(page); 

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  15. stephen
    stephen avatar
    3 posts
    Registered:
    21 May 2009
    03 Jun 2009
    Link to this post
    Hi Ivan

    I need to do something similar to this but I have several different templates and want the user to be able to select which template they are going to use.

    With this solution they don't get to choose which template they wish to use, is there a  way to intercept the selection of the template and then assign the controls based on a config file?

    Any help here would be great.

    Thanks

    Stephen
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Jun 2009
    Link to this post
    Hello stephen,

    You can set the template and theme programmatically as below:

    IPageTemplate pageTemplate = cmsManager.GetTemplate("Levels");  
    page.Staged.SetTemplate(pageTemplate.ID, "theme"); 

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
16 posts, 0 answered