Difference between revisions of "Page Templates:Creating a Basic Template"

From Whirlwind eCommerce Wiki
Jump to: navigation, search
(added head and html wrapper tags)
Line 21: Line 21:
 
// our opening html tags
 
// our opening html tags
 
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
 
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en"\ lang=\"en\" dir=\"ltr\">
+
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" dir=\"ltr\">
 
";
 
";
  

Revision as of 20:03, 3 December 2008

Page Template Managers

Create basic template

This example will help provide a good introduction to templates. While there are dozens and dozens of functions and core variables available, this template example will focus on just a few of the core variables and the menu bar functions to get your feet wet.


// always start your templates with any functions you require
// to gather the data you need for the page
 
// lets start by getting our menu bar data
// note that the menu bars are usually contained in component includes
// since they are reused on many templates, no reason to perform the task on each template
$menus = eV::pageMenuGet();
// for easy reference, lets separate the menus
$topMenu = $menus['t'];
$leftMenu = $menus['l'];
$bottomMenu = $menu['b'];
 
// our opening html tags
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" dir=\"ltr\">
";
 
// now for the head
// notice we use some core variables here to specify the title, meta keywords and description
// the contents of these variables are controlled by page management
// note the use of the php htmlspecialchars function to ensure no characters in the variable content 'break' the tags
echo "
<head>
<meta name=\"keywords\" content=\"" . htmlspecialchars($metaKeywords) . "\">
<meta name=\"description\" content=\"" . htmlspecialchars($metaDescription) . "\">
<title>" . htmlspecialchars($metaTitle) . "</title>
</head>
";
 
// start the body tag
echo "<body>";
 
// lets build an outer table to hold our page content
echo "<table width=779>";
 
// this is the top banner
echo "<tr><td align=center colspan=2><font size=6><b>WELCOME TO OUR WEB SITE</b></font></td></tr>";
 
// now for the top menu bar
// the menu bar data is controlled by menu management
// the data is accessed via the pageMenuGet function at the beginning of this example
// we take the returned associated array and assign each menu location to it's own array
// we are addressing the top menu here
// see the function pageMenuGet for more details on the data returned
// as we are only touching on what you can do with menus in this example
 
// we will start with a wrapping cell and preceding pipe
echo "<tr><td colspan=2> | ";
// now we loop through each item in the menu and output it
foreach($topMenu as $menuItem) echo "<a href=\"" . $menuItem['link'] . "\" target=\"" . $menuItem['target'] . "\">" . $menuItem['text'] . "</a> | ";
// finally lets close the wrapping cell
echo "</td></tr>";
// note that menu items will not appear here unless they are populated in menu management
 
// lets do the left column now
// the left column contains the left menu, so this will be similar to above
// starting with a wrapping cell
echo "<tr><td valign=top>";
// now we loop through each item in the menu and output it
foreach($leftMenu as $menuItem) echo "<br><a href=\"" . $menuItem['link'] . "\" target=\"" . $menuItem['target'] . "\">" . $menuItem['text'] . "</a>";
// finally lets close the wrapping cell
echo "</td>";
 
// now lets display the center page content
echo "<td valign=top>";
 
// first im going to display the message output
// this is a variable used to pass messages (errors, notifications, etc) from page to page for visitors
// you want this highlighted so it is brought to their attention
// only display this if it has value
if(!empty($attributes['message'])) echo "<font color=red>" . $attributes['message']] . "</font><br><br>";
 
// center page content
// pulled from core variables
// the contents of these variables is controlled via page management
echo "<b>$title</b><br><i>$subTitle</i><br><br>$copy";
 
// now lets close out the center content cell
echo "</td></tr>";
 
// time for the bottom menu
echo "<tr><td colspan=2 align=center> | ";
foreach($bottomMenu as $menuItem) echo " <a href=\"" . $menuItem['link'] . "\" target=\"" . $menuItem['target'] . "\">" . $menuItem['text'] . "</a> | ";
echo "</td></tr>";
 
// close out the outer wrapping table
echo "</table>";
 
// close out the body and html
echo "</body>
</html>";