Display Tutorials

  Home arrow Display Tutorials arrow Page 9 - Writing a Template System in PHP
DISPLAY TUTORIALS

Writing a Template System in PHP
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 69
    2004-01-13

    Table of Contents:
  • Writing a Template System in PHP
  • The Implementation
  • The Template File
  • The Class Skeleton
  • Constructor and Output
  • Replacing Tags
  • Including Dynamic Files
  • The Final Code
  • Tricks

  •  
     

    SEARCH CODEWALKERS

    Writing a Template System in PHP - Tricks


    (Page 9 of 9 )

    One example of just how powerful the class can be and just how easy it can make development is using it to highlight a menu's link to the active page.

    Place a style declaration similar to the following within the template's head section:

    <style type="text/css">
      #{activemenu} {color: red; font-weight: bold;}
    </style>

    The menu file would contain similar id attributes within its markup:

    <a href="link1.php" id="menuItem1">link 1</a>
    <a href="link2.php" id="menuItem2">link 2</a>
    <a href="link3.php" id="menuItem3">link 3</a>
    <a href="link4.php" id="menuItem4">link 4</a>

    The active link would then be highlighted by passing the appropriate id value to replace the activemenu tag found in the template file:

    <?php
    replace_tags
    (array(
      
    "menu" =&gt"dat/menu.dat",
      
    "activemenu" =&gt"menuItem3"
    ));
    ?>

    The templating class may be only 35 lines of code or so, but has limitless, untapped potential.

    About the Author

    Timothy Boronczyk lives in Syracuse, NY, where he works as an E-Services Coordinator for a local credit union. He has a background in elementary education, over 5 years experience in web design and has written tutorials on web design, PHP, Ruby, XML and various other topics. His hobbies include photography and composing music.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    blog comments powered by Disqus

    DISPLAY TUTORIALS ARTICLES

    - Smart Auto Refresh
    - Writing a Template System in PHP

    Developer Shed Affiliates

     



    © 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap