Templates are simply PHP views with some well defined PHP variables available. However, the ability to define and easily apply various templates is what makes our CMS so powerful.
Here is a simple template:
<!DOCTYPE html>
<html lang="en">
<head>
<title><?=$title?> › alasnome.com</title>
<link href="/assets/css/studies.css" rel="stylesheet" type="text/css">
</head>
<body>
<div>
<!-- Dynamic content goes here -->
<?= $content ?>
</div>
<div id="sidebar">
. . .
</div>
<script type="text/javascript" src="/assets/js/jquery"></script>
<!-- Dynamic scripts are inserted here -->
<!-- Dynamic tail is inserted here -->
</body>
</html>
The data from the scripts tab of the Page Editor is inserted into the page just before the closing </body>
tag.
The data from the content tab is assigned to the $content
PHP variable.
The title from the metadata tab is assigned to the $title
PHP variable.
There are other PHP variables defined for each page. Find a complete list of the variables that may be used in templates in the sidebar.
Template File Conventions
Each template file must:
- reside in the /application/views folder
- be prefixed with
tmpl-
- have a
php
extension - have an entry in the Template List as described below
Template List
In the Page Editor, on the Metadata tab, there is a drop-down list labelled Layout.
This list is populated from the file /application/models/tbls/layouts.csv. Here is an example:
tmpl,name
layout-1,Default Layout
layout-2,"Pink, Pink, Pink"
lo-3,My Favorite
Given the template conventions above, the above example layouts.csv file expects three files:
- /application/views/tmpl-layout-1.php
- /application/views/tmpl-layout-2.php
- /application/views/tmpl-lo-3.php
And, the drop-down for layout in the Page Editor would offer the following three options:
- Default Layout
- Pink, Pink, Pink
- My Favorite