D.E. Classifieds Documentation - Html Templates
A.functions{text-decoration:none; }
A:Hover.functions{text-decoration:none; color:#FF0000; }
Main Page
Creating html templates(For Html developers)
How the template system works(For PHP developers)
Creating Html Templates
There are a few basic things you need to do in order to create a new html template.
1. Create the template page.
2. Make sure your your template file has a ".php" extension.
3. Put the new template file in the "templates" directory.
4. make the appropriate changes in the "cnfg_vars.php" file.
Creating the template page
Create your html template file, insert the php tags that are listed below where
you want the associated behavior.
Make sure that the template file has a .php extension.
Your template file should be named something like myTemplate.php as opposed
to myTemplate.html or myTemplate.htm . This is really a php file! But for all intents and purposes you can regard it as an html file with a few special tags in it and a .php extension in the name.
Make sure your template file has a ".php" extension
This has already been covered, but it can't be stressed enough.
Put the new template file in the "templates" directory
Make sure your new template file is in the "templates" directory which
you should have already defined the path to in "path_cnfg.php".
Make the appropriate changes in the "cnfg_vars.php" file
Once you have created a new html template you need to let D.E. Classifieds
know to use it. You do this by going into "cnfg_vars.php" and changing
the value of the appropriate variable.
All variables pertaining to template file names will be prefixed with "tmplt_" .
After the "tmplt_" prefix will be the name of one of the pages of the application.
For instance "add_item.php" is the name of the page that D.E. Classifieds uses
when someone choose to add an item to the database. "add_item.php" is not the template file, but the actual php that is invoked in the application and that does most of the work. If you wanted to change the look of "add_item.php" you
would set "tmplt_add_item" to the name of your new template files.
Example:
'tmplt_add_item' => "myNewTemplate.php",
If you wanted to change the look of your home page you would change the
value of "tmplt_index".
Example:
'tmplt_index' => "homePageTemplate.php",
If you want to change which template file a particular page of the application
uses, but aren't sure what the name of the page is. Just navigate through the site to the page in question and look in the location bar of your browser.
The name of the page will be something like index.php or add_item.php.
If there is a question mark and stuff following it, don't worry about that stuff, it's extra stuff that the application uses. The name of the file comes before
the question mark.
Example:
http://myclassifiedsite.com/classifieds/search.php?doSearch=1
If the above is what you see in the location bar, then the name of the file for
the current page is "search.php".
Now you should know the basics of creating a template file.
Using the predefined tags
These are the tags that the application uses to actually do stuff.
If you create a template file but don't put any of these tags in it,
it will just sit there and not do anything but display the html that you
put in it.
Most of these tags are optional, but at least one is mandatory, that is " <?php content($content); ?> ".
The quotation marks are only used to distinguish the tag from the rest of the words in the sentence. Quotation marks should not be present in actual usage.
A brief description of how the " <?php content($content); ?> " tag works.
What the " <?php content($content); ?> " does depends on which page is
currently being served.
If you are at the home page then the " <?php content($content); ?> " tag will display the
Ideally, you will be able to copy and paste
the tags below into your html templates.
You may have to copy the tags that are lower down on the
page rather than copying the linked tags. Some text
editors may paste the linked tags as underlined html links.
Either way, you should copy the tag that you want to use directly
from this page.
<?php main_css(); ?>
<?php main_header(); ?>
<?php top_nav(); ?>
<?php display_cats_main(); ?>
<?php content($content); ?>
<?php log_in_form_and_status(); ?>
<?php log_in_form(); ?>
<?php log_in_status(); ?>
<?php main_footer(); ?>
<?php main_css(); ?>
This is where the CSS for the page is inserted.
This should always be present in the template file unless
you've made the appropriate changes in other parts of the script.
Various parts of the application depend on values that are defined in
CSS that is inserted here.
If you know what you are doing it would be best to put this CSS in it's own file and then call it using something similar to:
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css">
Not cluttering up the top of your html document could help you out in with the search engines.
Top of page
Template Tags
<?php main_header(); ?>
This is the stuff that will appear at the top of the page.
Top of page
Template Tags
<?php top_nav(); ?>
These are the links that the user clicks when they want to perform an action, for instance "edit", "search", "register", etc. .
It is also where the "home" link resides.
If you know html you can go into this function and change it to suit your needs. Then in your template file you can insert this function call to put the links wherever you want in the page.
Top of page
Template Tags
<?php display_cats_main(); ?>
This is where the links to the top-level categories are displayed.
Top of page
Template Tags
<?php content($content); ?>
This is where the main content for any particular page is displayed.
The content depends on which page is currently being displayed.
If you are on the search page, then this is where the search results are displayed. If you are browsing ads, this is where the results are displayed. If you are browing categories, it's where the sub-categories are displayed.
Top of page
Template Tags
<?php log_in_form_and_status(); ?>
Shows the login form when the user is not logged in.
Shows the "logged in as" message when the user is logged in.
Top of page
Template Tags
<?php log_in_form(); ?>
Shows the login form only.
Top of page
Template Tags
<?php log_in_status(); ?>
Shows "logged in as" message when user is logged in.
When user is not logged in it shows nothing.
Top of page
Template Tags
<?php main_footer(); ?>
This is the stuff that will appear at the bottom of the page.
Top of page
Template Tags
How the template system works
I thought the best thing to do was to use an html template file instead of having the html in every file of the application.
The way I decided to handle it was to do all the computing that I needed to do at the top of each file. And then include the html template file at the bottom.
When I want to output something, I put the code in an array that will be eval()'d inside of a function named "content".
The "content" function is in "func_common.php", but it is called from the template file.
When the "content" function is called, the $content array is passed to it.
It is passed by reference.
The name of the array that holds the code to be eval()'d is "$content" .
Since the code is eval()'d inside of a function, only variables within the function's scope are available.
The "content" function brings the $gbl array into its scope, so you can put any
values in there that need to be evaluated.
Example:
$gbl['content']['message'] = 'this is a message.';
$content[] = 'echo "$gbl['content']['message']";';
If you want to direct output to more than one section of the page from the html file, you can simply create additional arrays
and call the "content" function from another part of the page,
making sure to pass the appropriate array variable to the function.
For example:
$content[] = 'echo "this is content in one section of the page.";';
$content2[] = 'echo "this is content in another section of the page.";';
content($content);// evals code in $content
content($content2); // evals code in $content2
Just remember that array elements are being eval()'d one at a time. So "echo" statements or some other types of operations should not span more than one array element. Every array element should be a piece of self contained code.
If you need to do something beyond printing a simple string, you should probably make a function for it, then just put a function call in the $content array.
For example:
$content[] = 'printMessage();' ;
Just make sure that the current file has access to the "printMessage()" function.
If you are going to call a function from the
"content" function that needs to pass variable arguments, you should put the values in $gbl elements and pass the $gbl elements as the argument.
Example:
$gbl['content']['arg1'] = 'this is arg1';
$gbl['content']['arg2'] = 'this is arg2';
$content[] = 'printMessage($gbl[\'content\'][\'arg1\'], $gbl[\'content\'][\'arg2\']);' ;
By default, the application uses one template file named
"html_template1.php" .
This is actually a php file, and should keep the ".php" extension.
Since the sole purpose of this file is to manage the look of the output, which will pretty much all be html after it gets to the browser, I thought I'd regard it as an "html template".
The template file itself calls some functions from
"func_common.php".
These functions deal with getting info from the database for category navigation, and other things.
You DON'T have to limit yourself to using one template file.
For example say you wanted to make a different template for the search page.
In "search.php" you would specify the name of the template file in
the require statement.
Example:
require_once(path_cnfg('pathToTemplatesDir').'/my_new_template.php');
The value that is returned from path_cnfg('pathToTemplatesDir') is the path
to the "templates" directory that you set in the "path_cnfg.php" file.
A slash is not included at the end of the returned value, so you should
start the name of your template with a slash(/).
Top of page
Main Page
Wyszukiwarka
Podobne podstrony:
4 readme html email templateshtmlTemplatePart6templateeditDworak Iwona Templariusze (5)FREECHART template indd 1README HTML (2)DIY Mortis Dreadmought Plans & Templatesemail template product notificationtemplate?min!0002 HTML Themeshtmlwięcej podobnych podstron