Template on Page Create

Posted by Community Admin on 03-Aug-2018 17:41

Template on Page Create

All Replies

Posted by Community Admin on 04-Nov-2010 00:00
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
Posted by Community Admin on 04-Nov-2010 00:00
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
Posted by Community Admin on 12-Nov-2010 00:00
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
Posted by Community Admin on 13-Nov-2010 00:00
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
Posted by Community Admin on 15-Nov-2010 00:00
Regarding my GetTemplates() issue, more info here
www.sitefinity.com/.../pagemanager-gettemplates-not-working.aspx
Posted by Community Admin on 30-Mar-2011 00:00
how do you set the template when you create a page?

the SetTemplate method isn't in the API anymore.
Posted by Community Admin on 01-Apr-2011 00:00
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

This thread is closed