Filetemplates allow serving Midgard applications from files instead of the database. Filetemplates applications are easy to distribute and to maintain while retaining most of the possibilities of applications fully contained in the database.
Filetemplate applications can be used in two ways: connected and disconnected mode. Connected mode means that a connection will be made to the Midgard database and its content will be available under the same rules that they would be in a normal Midgard application. In disconnected mode there will be no connection with the database, but the style system and the formatter code will be available.
If a filetemplate request is being made against an apache host definition for which a non-prefixed entry exists in an associated database the request will be handled in connected mode, disconnected otherwise. The elements of the style that is associated with the host record will be available during the request. If the host record requires athentication it will be enforced.
Filetemplate files are XML files. There are page files and element files with the following syntax:
<!ELEMENT midgard (page?, (element*))> <!ELEMENT page (#PCDATA)> <!ATTLIST page title CDATA> <!ELEMENT element (#PCDATA)> <!ATTLIST element name CDATA> <!ELEMENT auth EMPTY> <!ELEMENT skiphoststyle EMPTY> <!ELEMENT stop EMPTY>
When a request is being made for a filetemplate file it will first be read, after which midgard will read the file specified by the MidgardTemplate apache directive, for example phpelements.xml, in the directory that holds the requested file and each directory in the path leading there.
Page containers are the equivalent of page records and hold the actual page content. Element containers are the equivalent of style and page elements. When they're in the page file they apply only to that particular file. If they're in an element file they will apply to any file in that directory and files in higher directories.
If the auth element is present in the page or element file authentication will be required. This only works in connected mode and will be ignored in disconnected mode.
If the skiphoststyle element is present in the page or element file the style elements from the style associated with the matching host record in the database will not be used. This only works in connected mode and will be ignored in disconnected mode.
If the stop element is present the search for element files in lower directories will stop. The entire file that holds the stop element will still be parsed. If this element is not present the search will continue down to and including the filesystem root. If you have a number of sites under /var/www/sites for example it would be plausable to have an element file there like:
<midgard><stop/></midgard>
The value of the $midgard object will have some limitations. The page field will be set to 0. In disconnected mode, or if skiphoststyle was present, the style field will be set to 0.