Creating Template Libraries

From Appmethod Topics
Jump to: navigation, search

Go Up to How To Edit Code in the Code Editor


Template libraries are custom project templates that specify how a project should look and what it should contain. When you create a custom template library, it is placed in the New Items dialog box where it is accessible for creating a project using File > New.

You can create template library projects from scratch, or you can use projects previously created by you or other developers as the basis for template libraries. To use an existing project, you simply create an XML file with the extension .bdstemplatelib which describes the project and is used to create the template library using that project.

Note: When creating a project to use with a template library, the project should be located in a subdirectory that contains no other projects. Also, all of the files in the project should be located within the subdirectory or its child subdirectories.

To Create a Template Library

  1. Create a new project or open an existing project that will be the basis for the custom template library. Make any modifications to the project to customize it for the template library.
  2. Save and close the project.
  3. Choose File > New > Other > WebDocuments and double-click the XML File icon.
  4. Replace the default contents of the new XML file with the following sample content:


  <TemplateLibrary Version="1.0" id="">
    <Name></Name>
    <Description></Description>
    <Items>
      <Item id="" Creator="">
        <Name>Name of template library here </Name>
        <Description>Custom Project Template</Description>
        <Author></Author>
        <Icon>MyTemplate\MyTemplateIcon.ico</Icon>
        <Projectfile>MyTemplate.dproj</Projectfile>
        <DefaultProjectName>MyTemplate</DefaultProjectName>
        <FilePath>MyTemplate</FilePath>
      </Item>
    </Items>
  </TemplateLibrary>


Important:
  • The id="" attribute of the <TemplateLibrary> element should be something unique to avoid conflicts with other template libraries. A good practice is to include your name or the name of your company as part of the id.
  • The Creator="" attribute in the <Item> element specifies which page of the New Items dialog box displays the icon for this template library. You can put the project icon on a specific page for the type of project it creates.
Below are the possible Creator="" attribute values:


Project Type Item Creator Attribute Value
C++ Projects Creator="CBuilderProjectRepositoryCreator"
Object Pascal Projects Creator="DelphiProjectRepositoryCreator"


  1. Save the .bdstemplatelib.xml file to a directory above the project directory.

    Note: The <FilePath> element in the .bdstemplatelib file indicates the location of the project directory relative to the location of the .bdstemplatelib file.

  2. Edit the .bdstemplatelib.xml content to customize it for your own template library:

    • Add the template library name, description, and Creator attribute value.
    • Edit the project name, project path information, icon path, and file name. Optionally, you can add your name as author.
    • Specify the relative path to the .bdstemplatelib.xml in the <FilePath> value. For example, if your project is in C:\MyProjects\TemplateLibraries\MyTemplate, and you put the XML file in C:\MyProjects\TemplateLibraries, the <FilePath> value in the XML file would be <FilePath>TemplateLibraries\MyTemplate</FilePath>.
  3. Choose Tools > Template Libraries to open the Template Libraries dialog box.
  4. Click the Add button, browse to and select the .bdstemplatelib.xml file you just created, and click Open.The new template library is added to the list in the Template Libraries dialog box. It is also added to the specified page of the New Files dialog box.Click OK to close the Template Libraries dialog box.

To use this template library for creating a new project, choose File > New > Other, and select your template library in the New files dialog box.

Example

  <TemplateLibrary Version="1.0" id="CompanyNameDelphiVCLProject">
    <Name>DelphiVCLProject</Name>
    <Description>Simple Delphi VCL Project</Description>
    <Items>
      <Item id="DelphiVCLProject" Creator="DelphiProjectRepositoryCreator">
        <Name>Delphi VCL Project</Name>
        <Description>A simple Delphi VCL project.</Description>
        <Author>John Doe</Author>
        <ProjectFile>DelphiVCLProject.dproj</ProjectFile>
        <DefaultProjectName>DelphiVCLProject</DefaultProjectName>
        <FilePath>DelphiVCL</FilePath>
      </Item>
    </Items>
  </TemplateLibrary>

If you have several related projects, you can use a single .bdstemplatelib template library file to list all the projects.

To Combine Multiple Projects in One Template Library File

  1. Put all the project folders at the same level in the same project sub-folder.
  2. Create the .bdstemplatelib template library file at the level above the folder containing all the projects.
  3. Add the content for the first project as described above.
  4. Add an additional <Item></Item> to the <Items></Items> element for each project in the group, giving each <Item></Item> a unique id=" attribute.

Example

  <TemplateLibrary Version="1.0" id="Embarcadero">
    <Name>MultipleProjectsTemplate</Name>
    <Description>Template with multiple projects.</Description>
    <Items>
      <Item id="DelphiVCLProject" Creator="DelphiProjectRepositoryCreator">
        <Name>Delphi VCL Project</Name>
        <Description>A simple Delphi VCL project.</Description>
        <Author>John Doe</Author>
        <ProjectFile>DelphiVCLProject.dproj</ProjectFile>
        <DefaultProjectName>DelphiVCLProject1</DefaultProjectName>
        <FilePath>DelphiVCL</FilePath>
      </Item>
      <Item id="CppVCLProject" Creator="CBuilderProjectRepositoryCreator">
        <Name>C++ VCL Project</Name>
        <Description>A simple C++ VCL project.</Description>
        <Author>John Doe</Author>
        <ProjectFile>CPPVCLProject.dproj</ProjectFile>
        <DefaultProjectName>CPPVCLProject2</DefaultProjectName>
        <FilePath>CPPVCL</FilePath>
      </Item>
    </Items>
  </TemplateLibrary>


See Also