Results 1 to 17 of 17

Thread: Template variable question...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448

    Template variable question...

    Im trying to get the title of the page to be read from my database. What i have done so far is tryed this. I made the table and entered the data into mySQL. Then i put a variable in the <title> tag in the template. And i defined the veriable in the php index part. But when i load the page it only shows the variable not the text in the database. Can you help me fix this?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Can you supply some code? From your description, I'm not exactly sure what you're doing.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    well i have my template,
    Code:
    <html>
    <head>
    <title>$title</title>
    </head>
    <body>
    $content
    </body>
    </html>
    and in my php file i have this...

    $title = "test"
    $content = "content"

    and nothing happens

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    The $title needs to be in PHP tags..... otherwise it doesn't get parsed out by PHP and ends up getting sent right to the browser try this:
    PHP Code:
    <html>
    <head>
    <title><?php echo $title?>
    </title>
    </head>
    <body>
    <?php echo content?>
    </body>
    </html>
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    but i have it running through php like this...
    PHP Code:
    <?
    include_once("template.tpl");
    $title = "test"
    $content = "content"
    ?>
    do i still need to do that php in the template?

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Muk108
    but i have it running through php like this...
    PHP Code:
    <?
    include_once("template.tpl");
    $title = "test"
    $content = "content"
    ?>
    do i still need to do that php in the template?
    Yes. PHP outputs included files to the browser as is until it reaches a PHP tag. Then it starts parsing it as PHP code until it finds a closing tag.

    So you do need them around $title:

    Code:
    <title><?php echo $title; ?></title>
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    What is they way you see templates used that have the {veriable} and they dont have the <? ?> around it? Im trying to do that so i dont have to have multiple includes. Can you ehlp me with this?

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    huh...?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    i think it has something to do with a template engine but im nto sure.

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Mind if I ask a question here... what is a .tpl template?

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Muk108
    i think it has something to do with a template engine but im nto sure.
    I have no idea what you're talking about anymore.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    i read somewhere that things like phpBB use template engines. and then somewhere i saw that a template engine is the thing that lets you use variables in your template so you dont have to use php. now i was wondering if you know how to do this? a .tpl file is just another way of nameing the template file. its still raw text just with a different extention like .php or .html etc.

  13. #13
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    vBulletin also uses a "template engine".

    Each individual part of a page is in a template.

    In the php file it is evaluated, so that any variables inside that template become normal text for the string e.g.

    $newsbits = eval(gettemplate("home_newsbit));

    or something

    then vBB has a main template for each page which encompasses all the evaluated templates and builds it for output.

    That's my understanding of the vbb one at least, perhaps John - the old admin could shed some light on it, as he's on the vbb project.


  14. #14
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    He's using the SMARTY template engine.... unfortunatly that's something outside my knowledge. If you want to know more about it, check out http://www.xoops.org -- their system uses the SMARTY templating system and they have links and people that might be more use.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    well, would you recommend any other "template engine" that is good because im not understanding this smarty one.

  16. #16
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Sorry... the only kind of templating I've ever done has been building my own....
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  17. #17
    New Member Sevengraff's Avatar
    Join Date
    Feb 2003
    Location
    California, USA
    Posts
    10
    Originally posted by Muk108
    but i have it running through php like this...
    PHP Code:
    <?
    include_once("template.tpl");
    $title = "test"
    $content = "content"
    ?>
    do i still need to do that php in the template?
    shouldn't you define the variables before you include the template?

Posting Permissions

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



Click Here to Expand Forum to Full Width