The Template System

Introduction

AutoKB has a powerful template system that allows you to change the look and layout of your knowledge base. The template system provides an easy way for you to edit the look of the knowledge base without having to edit a single line of PHP code. As long as you have a solid understanding of HTML, you can easily modify the templates so that your knowledge base can integrate seamlessly into the rest of your website.

Control Panel Editing Interface

All changes to your templates will be made through the control panel. From the control panel menu, locate and click on the Edit Templates link to access the built in template editor. AutoKB will load a page where you will be able to select which of the templates you want to edit. Select the template you want to edit from drop down selection list, and press the Load Template button.

You will be returned to the same page, however now there will be a large text input box where you will edit the HTML code of the template. The first time you do this, the text input box will contain AutoKB's default HTML. You can edit that HTML or paste your own HTML code into this text input box. When you are satisfied with the changes you have made, press the Save Template button. This will save a copy of the template and pre-compile the template so that the page can be rendered quickly when it is accessed.

Before Making Changes

Before you start making changes to the default HTML, it is recommended that you look it over and try to understand it. Seeing an example of how the template system works should make it easier for you to create your own templates. It is also recommended that you add a few test articles and glossary words to see how they are displayed with the default template.

Template Values

When you edit the templates you will notice in several places text that is surrounded by ## characters. For example, on the index_article.tpl template (which is used when viewing an article in the knowledge base) the value ##Topic## appears. This value is a special value for the software which will be replaced by the article's topic when the page is rendered. Because these are special values you should not use any text on your page that uses this same format. If you do, it will be removed by the software before the page is rendered. Only recognized template values will be replaced by the software.

Some template values are valid only inside template sections (described further on in this document) and some are valid anywhere on the page except inside template sections. The template values that are valid only inside template sections are called local template values. Those template values that are valid anywhere except inside template sections are called global template values.

Now for a quick example. Suppose you are working on a template which has two valid template values, ##Date## and ##Time##. You may then have the following HTML code somewhere in your template: Since ##Date## and ##Time## are valid template values, AutoKB will have already calculated the current date and time so they can be placed in the template. When AutoKB parses the template, it will come across the ##Date## and ##Time## template values. Those two values will be replaced by the date and time that AutoKB has calculated. Assuming AutoKB has calculated the date as January 1st, 2003 and the time as 7:00am, the following HTML would be generated based on your template: Further on in this document all of the valid template values for each template will be listed, along with a description of what they will display when they are parsed and rendered by AutoKB.

Template Sections

Besides template values there are also template sections. A template section gives AutoKB information on what type of data should be displayed in a certain section and how it should be displayed. Each of the template files have their own sections that you can use, and all of the available template sections will be described in detail further on in this document.

Sections are defined in your template by an opening and closing tag. Each of the tags starts with an opening curly brace { and ends with a closing curly brace }. For example, you might have a section that is named articles with an opening tag of {articles} and a closing tag of {/articles}. Note that the closing tag is the same as the opening tag with the exception that a forward slash is placed before the section name. All sections must contain both an opening tag and a closing tag or the template will not work properly.

Here is an example of what a section might look like, using the articles example: Notice that the section opening and closing tags are on a line by themselves. This is required and failure to follow this format will result in templates that do not work correctly. It is also possible to have nested sections, where one section is contained within another. Here is an example of that: Notice that the nested section name is noarticles and it's opening and closing tags are completely contained within the articles section. Again, the nested section's opening and closing tags are on a line by themselves.

Details on Each Template

Each of the templates used by the software has it's own set of valid template sections and values. This portion of the document will cover each of the templates that you can edit, including their valid template sections and values. One template section can be used on any of the templates, so it is covered first.

{include}
{/include}

This template section can be used to include the contents any file from your webspace into the template when it is rendered. Simply place the full directory path to the file that you want to include inside this template section. You can also use a virtual path that is relative to the directory that your knowledge base is installed in.