Template containing editable tables and sampletext?

How do I create a template that will create a new webpage with already supplied headlines, tables and sampletext? These "objects" must be fully editable by the editors of that new webpage.
May 24, 2006 10:03
Anyone? All I need is a way to insert html into a property like MainBody, when the webpage is created.
May 29, 2006 9:42
Hello Markus, I can see a couple of possible solutions for you. 1) Set the desired default value in the property definition for the page type (or dynamic properties) in Admin mode. 2) Add a custom event handler for a suitable DataFactory event, to run your custom code to set default values for any properties you desire. You could attach to the DataFactory.CreatingPage or LoadingDefaultPageData or similar, depending on when you want your code to run. In the event handlers, you can access PageEventArgs.Page and retrieve/set any property values from the page as you desire. 3) If you have created a custom UI to create the pages (that is, editors are not creating them from EPiServer's Edit mode), you can set the property values as you please from the C# code that creates the page. Again, you would use the DataFactory to achieve this, starting with the GetDefaultPageData method to create a PageData object that you can set your desired property values in (and then save/publish it). The first approach is of course the most basic, requiring no code or customization at all. Simply enter the default value(s) in Admin mode, and you're set. However, this is limited to static values. The other approaches offer you more detailed control, and you can set the values based on any logic (checking which user is creating the page, the date, in what branch of the web site the page is created, etc etc). The event handler approach is probably suitable if your desired feature is to be rather generic - for instance always setting the property "WriterName" to the name of the logged on user that is creating the page, regardless of how the page is created or where. You can also add checks to make the code run only when certain page types are being used, or similar. The third approach relies on users creating the pages through your own UI. For instance in a Discussion forum or similar feature on your web site, you offer buttons for "New topic" or whatever. In the C# code handling the creation of such new pages, you can modify the PageData object as you please, before saving it. Hope this helps - if not, please provide some more detail.
May 29, 2006 15:42
It sounds like DataFactory.CreatePage is what I need. I'm trying with the sample projekt that's included with 4.60. I've found this bit of code in SDK: protected void Application_Start( object sender, System.EventArgs e ) { EPDataFactory.CreatingPage += new EPiServer.PageEventHandler( OnCreatingPage ); } private void OnCreatingPage( object sender, EPiServer.PageEventArgs e ) { if ( e.Page.Property.Exists( "WriterName" ) ) { if ( e.Page.Property[ "WriterName" ].IsNull ) { e.Page[ "WriterName" ] = ( EPiServer.Security.UnifiedPrincipal.Current.UserData.Email !=null ? EPiServer.Security.UnifiedPrincipal.Current.UserData.Email : EPiServer.Security.UnifiedPrincipal.Current.UserData.DisplayName ); } } } Should this code be inserted into my codebehind file(page.aspx.cs) or into global.asax? I only want to set Properties in this template, not all of them. Don't know what more details I can give you. What I'm trying to do is make a template that acts like a Word Template. When a editor creates a new webpage from a specific template he will get a webpage that has all the headlines, sampletexts and tables he needs. Which all are fully editable. I've only been(yet) to the Webdesigners course, that's why I'm asking simple questions.
May 30, 2006 10:47
You would enter the code into global.asax - you need to attach to an event that fires on the creation of pages, which will mean your code will run for every created page (regardless of page type). However, just as the sample code checks that there is a WriterName property, you can access any properties and meta data in the PageData object. So use the PageData.PageTypeID or PageTypeName properties to add checks to your event handler so your code runs only for the desired page type: if(e.Page.PageTypeName == "WordTemplatePageType") { ... } (The page templates and their code-behind files, such as page.aspx.cs, are only used to render/display the pages of one or more page types. That would be the wrong place to attach the event handler in this case.) As for what event you want to attach to, I believe the CreatingPage event will fire AFTER the editor has filled in any values and has initiated a save of the page. Since you would like to make sure that some property fields (such as MainBody) already contains some content when the editor creates the page, I believe the LoadedDefaultPageData event could be suitable. Hope this helps
May 30, 2006 11:54
Thank you for your help! It works great. It now inserts a copy of a webpage from EPiServer into the new page's Mainbody. This means that the editor themself can edit both the template pages and the final page without any assistance :) protected void Application_Start(Object sender, EventArgs e) { EPiServer.Global.EPDataFactory.LoadedDefaultPageData += new EPiServer.PageEventHandler(EPDataFactory_LoadedDefaultPageData); } private void EPDataFactory_LoadedDefaultPageData(object sender, EPiServer.PageEventArgs e) { if(e.Page.PageTypeName == "rutinmall") { EPiServer.Core.PageData oPage = EPiServer.Global.EPDataFactory.GetPage(new EPiServer.Core.PageReference(320)); e.Page["Mainbody"]=oPage["MainBody"]; } else if (e.Page.PageTypeName == "objektmall") { EPiServer.Core.PageData oPage = EPiServer.Global.EPDataFactory.GetPage(new EPiServer.Core.PageReference(321)); e.Page["Mainbody"]=oPage["MainBody"]; } else if (e.Page.PageTypeName == "nätmall") { EPiServer.Core.PageData oPage = EPiServer.Global.EPDataFactory.GetPage(new EPiServer.Core.PageReference(287)); e.Page["Mainbody"]=oPage["MainBody"]; } }
Jun 01, 2006 13:59
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.