Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    Template Engine?

    I am looking for something that will do the following.

    I have a html document that i can do the normal template things.
    PHP Code:
    <html>
    <
    head>
    <
    title>{:pagetitle:}</title>
    </
    head>
    ... 
    Then i want to have a file that lists things like
    PHP Code:
    pagetitle --> $result['tuturl'
    What is different from other ones of these that i have found online, is that instead of replacing it with static content like
    Code:
    pagetitle --> THIS IS A PAGE TITLE
    Im using something that goes like:

    PHP Code:
    $query="SELECT * from tutorials WHERE id='$_GET[id];'";
    $row=mysql_query($query) or die(mysql_error());
    $result mysql_fetch_array($row); 
    and so lets say i go to a page with a url like:

    ...viewpage.php?id=3

    it opens the html file for viewpage, and parses the viewpage template which is like that of my first code above, and takes the tuturl and puts it into the title...

    Might sound like any template script, except i want mine this to be dynamic depending on the id in the url and the like.

    Does anyone know of one like this, or script that i can work with?
    Or if not...then just plain out...how do i do this?

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,095
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Hi, templating is usually at least a 2 part process, often 3.

    e.g. You have the actual template ..e.g.
    Code:
    <!--/path/to/template.tpl-->
    <h3>{C_TITLE}</h3>
    <span class="para">{C_BODY}</span>
    <span class="para">{C_COMMENTS}</span>
    then a routine for gathering the data to replace which might for example look like this..
    PHP Code:
    <?php
    $sql 
    mysql_query("
        SELECT c_title,c_body,c_comments 
        FROM $table 
        WHERE id='{$_REQUEST['id']}'"
    );
    $r mysql_fetch_assoc($sql);
    ?>
    then you can either just parse the tempate there and then, OR pass the data ($r) to a templating function or class.. the former...

    PHP Code:
    <?php
    $tpl
    file_get_contents('/path/to/template.tpl');
    $content str_replace(
        array(
    '{C_TITLE}','{C_BODY}','{C_COMMENTS}'),
        array(
    $r['c_title'],$r['c_body'],$r['c_comments']),
        
    $tpl
    );
    echo 
    $content;
    ?>
    how far you go with templating is another matter , my personal template class has simple IF and INCLUDE support and the ability to iterate through sections and auto-replace certain constants , some templating systems introduce nearly thier own language which I personally think is counter-productive but each to thier own.

    Anyways, thats the basics.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    ok, i think i can use that, now, to make it easy to add things, how can i do a simple looking thing like:

    PHP Code:
    {:title:} => .$row['title'].
    {:
    author:} => .$row['author'].
    {:
    cata:} => .$row['category'].
    {:
    date:} => .$row['date']. 

  • #4
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    smarty.php.net

    Hello i think you are looking for some template engine.
    If you have some time you can look at above address.

    Regards
    www.takedom.com

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by thesavior
    ok, i think i can use that, now, to make it easy to add things, how can i do a simple looking thing like:

    PHP Code:
    {:title:} => .$row['title'].
    {:
    author:} => .$row['author'].
    {:
    cata:} => .$row['category'].
    {:
    date:} => .$row['date']. 
    PHP Code:
    $content file_get_contents('tpl/page.tpl');
    $content str_replace('{:title:}'$row['title'], $content);
    $content str_replace('{:author:}'$row['author'], $content);
    $content str_replace('{:category:}'$row['category'], $content);
    $content str_replace('{:date:}'$row['date'], $content);
    echo 
    $content
    "$question = ( to() ) ? be() : ~be();"

  • #6
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    zombbb...that is a website selling hosting, i don't want hosting, i want to know how to make one of these on my site...i didn't see what im looking for anywhere there.

    and thanks velox, ill use that.

  • #7
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I believe he meant the address in the title:
    http://smarty.php.net/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •