- Name Template
- CSS Class NA
- Type NA
The Template class works as an intermediary between the Chan.Page's ASPX
and a raw HTML file. It takes the contents of the ASPX, as well as
any script and style definitions and places them in pre defined "Regions"
within the HTML file.
In order to use a Template you must first create it and bind it
to your page in the Page's Template_Init() method. This method is
called before any other Page event especially for template binding.
It is possible to assign the template at any point up to and including
the Page_PreRender function, but this would be considered an advanced
use case and is not recommended for simple sites. Instead you should
create a base Page class that impliments Template_Init and derive
your site's pages from that.
Built In Regions
These are automatically populated when the Page is rendered, so setting them from your own code will have no effect on their final contents
| Qualifiers |
Name |
Description |
|
Head |
This should go at the top of the HEAD block in the HTML and will contain references to the Chan CSS and JS resources as well as any scripts specified in Page.Page_Scripts and Page.Page_Styles |
|
Content |
This is where the contents of the ASPX are rendered into the HTML, Excluding any Panels that have Region set. |
|
Title |
A combination of Page.Page_Title and web.config:Chan_Site_Title. These are joined by a hyphen depending on web.config:Page_Title_Position |
|
Page_Title |
The Page.Page_Title for the current Page |
|
Site_Title |
web.config:Chan_Site_Title |
|
Keywords |
This will contain a META tag combining Page.Page_Keywords with web.config:Chan_Site_Keyboards |
|
Description |
This will contain a META tag combining Page.Page_Description with web.config:Chan_Site_Description |
|
Http_Root |
web.config:Chan_Http_Root, without any trailing slash |
|
Site_Root |
web.config:Chan_Site_Root, without any trailing slash |
|
Chan_Root |
web.config:Chan_Chan_Root, without any trailing slash |
Properties
| Qualifiers |
Type |
Name |
Default |
Description |
|
string |
[ string ] |
|
The default accessor allows you to set the contents of each region directly, new Regions are created automatically if they do not exist. |
|
string |
Template |
|
The path to the file on disk that contains the templated HTML, it can be a full absolute path ("C:\private\templates\home.htm"), relative to the web site root ("/templates/purple.htm") or contain escaped Chan Paths ("[Chan_Fragments]/basic.htm"). |
|
HashTable |
Regions |
|
This is the actual collection that houses the Regions in the form of key/value string pairs, you can manually add and remove regions by referencing this collection. |
Methods
| Qualifiers |
Type |
Name |
Parameters |
Description |
| public |
Template |
|
() |
The default constructor |
| public |
Template |
|
( string _TemplateFile) |
Overloaded constructor allowing you to specify the template filename |
| public virtual |
void |
PreRender |
() |
This is the final function to be called before Page Rendering, after Page.PreRender |
| protected |
void |
Set |
( string Key , string Value ) |
Allows you to set the contents of a Region wether or not it already exists in the Regions HashTable, if it does not the Region is created |
| protected |
string |
Get |
( string Key ) |
Allows you to get the contents of a Region wether or not it already exists in the Regions HashTable, if it does not it returns "" |
| protected virtual |
string |
Tag |
( string Key ) |
By default this returns String.Concat( "<!--" , Key , "-->" ). By overloading this function you can use any escaping scheme you desire. |
| public virtual |
string |
FallBackRender |
() |
By default this returns a HTML string containing a Strict DocType with only the Head, Title and Content regions set, it is used if no TemplateFile is defined or the file can not be found. |
Regions are defined in the HTML as if they were comment blocks - this
allows unfilled regions to remain inconspicuous. A basic HTML template
might look like the following:
To bind the Template to the page the above could be saved as "MyTemplate.htm" under a
folder named "templates" in the web site's root and then referenced thus:
To define custom regions in your template simply write them into your HTML...
The you can reference them directly from code...
Or fill them using Chan Panels:
The final output of the above will look similar to the following: