Template system

PythonPython Forum LeaderThe Royal RAM
My next step in php is to tro to learn how to use a template system. by this i mean where i can have a page called index.php and the design would be determined by index.tpl

Then id like to be able to do what phpbb templates do and have {SOMETHING_COOL} to display a certain text or item.

Anyone know of any tutorials on this?

The Royal Ram

Comments

  • tonytony Moderator Administrator
    you could try webmonkey.com
    not sure if they have any but they have tutorials for pretty much everything else
  • PythonPython Forum Leader The Royal RAM
    i had a quick look and i couldnt find anything about it. i did have some other good tutorials though

    The Royal Ram

  • ChroderChroder Senior Member The Royal RAM
    It's quite simple Python, basically you load the file (ie. 'index.tpl') then search for {SOMETHING_COOL} and replace it with "Something else". For example:

    [code:1:f73c78e1e3]$tpl = file_get_contents('index.tpl');
    $tpl = str_replace('{SOMETHING_COOL', 'Something else', $tpl);

    echo $tpl;[/code:1:f73c78e1e3]

    Of course, you'd probably stick this into a class of some sort.
  • PythonPython Forum Leader The Royal RAM
    yeah. ill have a quick search on google sometime for a more detaled tutorial on it. because it would be really cool if i could make it based on language files too :)

    The Royal Ram

  • ChroderChroder Senior Member The Royal RAM
    What you could do is make an array of your language texts, then loop through them.

    [code:1:51e8a5b040]$lang = array('hello' => 'Hello', 'welcome' => 'Welcome to DD', 'time' => 'It\'s time again!');

    foreach($lang AS $k => $v)
    {
    $tpl = str_replace("{LNG.$k}", $v, $tpl);
    }

    echo $tpl;[/code:1:51e8a5b040]

    So in that example, {LNG.hello} would be replaced with 'Hello' etc.
  • basher772000basher772000 Beginner Link Clerk
    hey thats for those discriptions i have been learning php for some time my forum is http://www.zackszone.com so im going to be making some things for a new site
  • PythonPython Forum Leader The Royal RAM
    hi basher,

    thanks for joining in and posting but it would be better if you didnt spam.

    The Royal Ram

  • basher772000basher772000 Beginner Link Clerk
    Hey Python i wasnt trying to spam i was sent here but a freind thats builds websites and i was reading about php and saw this and it helped me with the site im putting to gether
    sorry if you though it was spaming i will not do it again
  • PythonPython Forum Leader The Royal RAM
    ahh i see. its ok.

    i wont count it against you :)

    so why dont you introduce yourself. maybe even get some reviews on your site at our reveiws section

    The Royal Ram

  • tntcheatstntcheats Senior Member The Royal RAM
    Welcome to the forums.

    Python, I've been looking for this sort of a thing for a while and never thought to ask. Thanks for posting the thread, and I'll be sure to read it when I start learning a little more PHP; at the moment I probably could understand it, I'm just not willing to without being in must-learn-PHP-mode.
  • basher772000basher772000 Beginner Link Clerk
    Well ok i guess ill introduce myself well im zack i build web sites for fun and just recently made a web forum using phpBB2
  • tntcheatstntcheats Senior Member The Royal RAM
  • ChroderChroder Senior Member The Royal RAM
    Welcome Zack.

    Hmm, phpBB has no split feature apparently.
  • PythonPython Forum Leader The Royal RAM
    lmao,

    its does its just i havent got a clue how to split topics, hehe.

    ill learn soon

    plus your a mod :)

    The Royal Ram

  • celicaukcelicauk Beginner Link Clerk
    Hi

    Check out the articles on Devshed.com, there is a five part series on there about building a site engine CMS, its a little incomplete but it has a lot of good ideas. I am working a version at the moment using PHP 4. Templates are XML based so I am writing a parser that emulates the simpleXML functionality in PHP5.

    Cheers

    Simon
Sign In or Register to comment.