Developer FAQ

How to add a new XHTML template to Composite C1 programmatically?

Answer:

Before adding a new XHTML template to Composite C1, you need to create and add it to App_Data\PageTemplates manually as an XML file. Then add this new XHTML template to Composite C1, using the C# function.

For Composite C1 v. 4.0 or later:

using System;

using Composite.Data;
using Composite.Data.Types;

namespace Composite.Tools.Installation
{
    public class NewTemplate
    {
        /// <summary>
        /// This function can be used for new template creation
        /// </summary>
        /// <param name="gTemplateGuid">Passing identifier for this template</param>
        /// <param name="sTitle"> Passing title for this template 
        /// (title corresponds with the name of xml file that contains markup for this template, it stores in App_Data\PageTemplates)
        /// </param>

        public static void CreateNewTemplate(Guid gTemplateGuid, string sTitle)
        {
            using (DataConnection connection = new DataConnection())
            {
				IXmlPageTemplate data = DataConnection.New<IXmlPageTemplate>();
				data.Id = gTemplateGuid;
				data.Title = sTitle;
				data.PageTemplateFilePath = String.Format("/{0}.xml", sTitle);
				connection.Add<IXmlPageTemplate>(data);
            }
        }
    }
}

Download the source

For Composite C1 v. 3.2 or earlier (to be deprecated):

using System;

using Composite.Data;
using Composite.Data.Types;

namespace Composite.Tools.Installation
{
    public class NewTemplate
    {
        /// <summary>
        /// This function can be used for new template creation
        /// </summary>
        /// <param name="gTemplateGuid">Passing identifier for this template</param>
        /// <param name="sTitle"> Passing title for this template 
        /// (title corresponds with the name of xml file that contains markup for this template, it stores in App_Data\PageTemplates)
        /// </param>

        public static void CreateNewTemplate(Guid gTemplateGuid, string sTitle)
        {
            using (DataConnection connection = new DataConnection())
            {
                IPageTemplate data = DataConnection.New<IPageTemplate>();
                data.Id = gTemplateGuid;
                data.Title = sTitle;
                data.PageTemplateFilePath = String.Format("/{0}.xml", sTitle);
                connection.Add<IPageTemplate>(data);
            }
        }
    }
}
Download the source

Note: This function simply “registers” a new XHTML template in Composite C1, by adding a reference to it to.

For Composite C1 v. 3.2 or earlier:

  • SQL provider: [Composite_Data_Types_IPageTemplate_public] table ()
  • XML provider: \App_Data\Composite\DataStores\Composite.Data.Types.IPageTemplates_public.xml

For Composite C1 v. 3.2 or earlier (to be deprecated):

  • SQL provider: [Composite_Data_Types_IXmlPageTemplate_public] table ()
  • XML provider: \App_Data\Composite\DataStores\Composite.Data.Types.IXmlPageTemplates_public.xml

The markup of the template (including the number of content placeholders) is defined in the XML file.

Here is the sample how to call this function:

Guid gTemplate = Guid.NewGuid();
NewTemplate.CreateNewTemplate(gTemplate, "MyCustomTemplate");