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

Forums / General Discussions / Template on Page Create

Template on Page Create

7 posts, 0 answered
  1. Jaime Weise
    Jaime Weise avatar
    120 posts
    Registered:
    02 Nov 2008
    04 Nov 2010
    Link to this post
    How do I get the ids for the stock templates?
    I am doing a lot of page generation. I have figured out how to create pages and add controls and modules. I haven't figured out yet how to add a template. 
    PageManager pManager = new PageManager();
            Guid templateGuid = pManager.GetTemplates().First().Id;
             
            App.WorkWith()
                   .Page()
                   .CreateNewStandardPage(PageLocation.Frontend)
                   .Do(p =>
                   {
                       p.Name = "Page1";
                       p.Title = "This is a test page";
                       p.Description = "Some Description here";
                       p.DateCreated = DateTime.Now; //filled in automatically, but you can control it programatically as well
                       p.UrlName = "page1";          //filled in automatically, but you can set any url name here.
                       p.ShowInNavigation = true;
                   })
                   .SetTemplateTo(templateGuid)
                   .SaveChanges();
            SiteMapBase.Cache.Flush();

    This code appears to add a template but I don't see the SetTemplateTo Method in the API.
    Where this is shown in the example
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Nov 2010
    Link to this post
    Hi jaime,

    You can use GetTemplates() method of PageManager class. The method returns IQueryable<PageTemplate>.

    Sincerely yours,
    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. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    12 Nov 2010
    Link to this post
    The GetTemplates() method hasnt been working for me, so this is what I did.
     - the SF database, I did select * FROM sf_page_templates
     - the id field has the guids for the templates in there, the title_ has the description
     - in the code I did
     - var templateGuid = new Guid("f669d9a7-009d-4d83-bbbb-000000000007");

    To replace the following in the Fluent API example
    var templateGuid = pManager.GetTemplates().First().Id;

    hth
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    13 Nov 2010
    Link to this post
    Hello Phillip,

    I am not able to replicate any issues with GetTemplate method with the latest internal builds.

    var manager = PageManager.GetManager();
    var templates = manager.GetTemplates();
    foreach (PageTemplate t in templates)
    {
        var n = t.Name;
        var id = t.Id;
    }


    Best wishes,
    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
  5. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    15 Nov 2010
    Link to this post
    Regarding my GetTemplates() issue, more info here
    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/pagemanager-gettemplates-not-working.aspx#1416740
  6. Dave
    Dave avatar
    16 posts
    Registered:
    10 Feb 2010
    30 Mar 2011
    Link to this post
    how do you set the template when you create a page?

    the SetTemplate method isn't in the API anymore.
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    01 Apr 2011
    Link to this post
    Hi,

    Each PageData object has a property Template which you can use to set a template.

    pagedata.Template = pageManager.GetTemplates().First();
    pageManager.SaveChanges();
    SiteMapBase.Cache.Flush();

    Best wishes,
    Ivan Dimitrov
    the Telerik team

7 posts, 0 answered