tpl format crash course

tpl format is a templating system and core component of ShiftLibrary. It has been built from the ground up and structured with both designers and developers in mind. Designers are not expected to be coders but should know their way around HTML.

Key advantages of tpl format

  • Designer and developer friendly
  • Dreamweaver friendly
  • Human readable urls
  • Files are more organised
  • Less repeated code
  • 404 notifications
  • Auto page titles

tpl format folder structure

root ----
	|
	---- _inc
	|
	---- _lib
	|
	---- _tpl
		|
		----- template.php

_inc folder contains configuration files: namely config.php and custom.php.
_lib folder is linked to a collection of shared libraries.
_tpl folder is where all the templates go.
template.php is the main template file.

Anatomy of a template

Webpages from the same website tend to share a lot of the same content. Most webpages will have the same header / navigation / footer and sometimes side navigation. They will then have some content in the middle which is totally unique to that page.

template.php is the content of that typical page minus the unique content. In the place of the unique content is a placeholder: <=$include_content;?>

Adding pages

Adding pages is simple. Just create a file in the template folder e.g. about.php. Note that the file extension is always php. Populate the new file with the unique content. Note that the unique content is the middle part of the page and should not contain any <html> or <body> tags.

You can now access this page from http://<your-domain>/about
And link to this page like so: <a href="about">about us</a>
note the absence of .php

To create an index page you should call the file index.php

You can also ceate folders within the _tpl folder. So you could create a folder called news. And within that you could have an index page and an article page.

root ----
	|
	---- _tpl
		|
		----- news
		|	|
		|	----- article.php
		|	|
		|	----- index.php
		|
		----- template.php

These new pages would be accessed like so:

http://<your-domain>/news/article
http://<your-domain>/news/

Multiple templates

In the above example you could also have a completely separate template for the news section. e,g,

root ----
	|
	---- _tpl
		|
		----- news
		|	|
		|	----- article.php
		|	|
		|	----- index.php
		|	|
		|	----- template.php
		|
		----- template.php

In this case the template.php in the news folder will be used instead of the one in the root.

404 notifications

By default 404 notifications are automatically emailed to ShiftCreate.

You can create a custom 404 error by creating a template file called 404.php in the tpl folder.

Auto page titles

Unique page titles are inportant as they are used by search engines, bookmarks and tabs.

templates are automatically scanned for the first heading tag e.g: <h1>page title</h1>.
The content of the h1 tag can then be used in the page title.

You can add it to your template page like so:
<title>My site | <?=$title ? $title : 'default page title';?></title>

The default title is used when the included page does not contain a h1 tag.

These titles can be over-rided on a per-page basis by defining $title at the top of the include.
e.g. <? $title='Use this title instead'; ?>

Sitemaps

An XML sitemap is automatically generated and can be sunmitted to google.
It is located here: http://<your-domain>/_lib/sitemap.xml.php

config.php

This file is located in the _inc folder.
It contains the site configuration including database login details and rhe default email address.

custom.php

This file is located in the _inc folder.
It contains custom functions specific to the site.

Reserved php variables

$include_content
$title
$auth
$request
$current_tab

Reserved page names

admin
logout