Important alert: (current site time 7/15/2013 9:59:34 AM EDT)
 

article

A Sample HTML Template using BFCTemplate v2

Email
Submitted on: 5/26/2001 5:00:53 AM
By: Christopher Brown-Floyd  
Level: Intermediate
User Rating: By 4 Users
Compatibility: PHP 4.0
Views: 20059
(About the author)
 
     The purpose of this article is to show new BFCTemplate users how to take full advantage of the template class.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				
First, I'll begin with a basic HTML file.

 
 This is some sample text
 

Now that we've established what a basic HTML file looks like, we can go into making it into a template for PHP. Here's what we need to do:
Just like about we have our HTML file; however, whereever we want to have dynamic data, we put a template tag like this:

 
 
 

Save the above file as "sample.tpl".
Once the template class is loaded, you can call the tag function for that tag like this:
usetemplate("sample.tpl");
$template->tag("MyTag","This is some sample text.");
$template->display();
?>
Save the above as "sample.php".
When you run the above file, you should get the following HTML output:

 
 This is some sample text<
 

Now, you may say, "That isn't that great. Why would I need a class to do that?" Ok, ok. I agree too, but let me show you how this class will make money for you.
Let's just say that you wanted to create a form from some data that was pulled from a database. Here's how you would create that form using this class:

 
 
Email:
Website:
Message:
What does this do? Weeelll...When the tag function is called, it checks the tag for the "as" attribute. This attribute tells it how to render the tag. However, you can also override it by using the override attribute of the tag function. Here's the syntax: tag([tag name],[value],[override tag name]); If the override attribute is not set, it'll use the default. So, that's it. There are more tricks that can be done with this class, but I'll save them for another article.


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

5/11/2005 12:05:25 PM

sdf
(If this comment was disrespectful, please report it.)

 
6/10/2010 4:34:29 AMahmed

thanks for you
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.