Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    Ive just finished writing the beta of my CMS and would like to know how to create a templating system with php. I found this tutorial http://codewalkers.com/tutorials/58/8.html but dont really understand itcan anyone simplify it or provide me with an example or 2
    Regards Phil,


  2.  

  3. #2
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    Generally you will want to do the following in order:
    1. Search and enumerate all template tags in the page
    2. Obtain the information needed to fill all of those tags
    3. Execute a search-and-replace on the original file to insert the information in step 2.

    Generally you will want to extract the entire file into a string on its own. Then you...
    1. Do a search for all tags you expect, with a Regexp if you want extra flexibility. If a tag is found, remember it in another array.
    2. Go through that array and obtain the information you need. Insert these into a new array.
    3. Do a second search for the tags, but this time replace them with information from that last array.

    Another aproach would be to do a linear search, which would be several times more effective, but slightly more complex. Use this method if you're confident you can make it work properly. In this case, you would do a search, immediately grab the new data, and plaster it there.

    The most optimized version would, of course, to store the results in real files and let users access those files, and have the templating system do changes to the files only when the information should be updated. This prevents the need to redo the entire search on each request, but would be quite a challenge.
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  4. #3
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    Sounds like I need a bit more php knowledge than I actually have
    Regards Phil,



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:25 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com