...PHP Include in TPL scripts

Discussion in 'PHP' started by tobydawson13, Dec 21, 2008.

  1. #1
    How do I go about including PHP scripts in TPL scripts? Or vice versa including TPL scripts in PHP scripts?

    Thanks for your help :)
     
    tobydawson13, Dec 21, 2008 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    To include php functions in a template it must end in .php or the server must be set up to parse that .ext (extension).

    The syntax for including a file is include ("pathto/filename.xxx").

    The options are include, include once, require. Most times the one above is all you will need.

    If the file is in the same directory the pathto/ is not needed. Paths may be relative ( ./ ../ ) or specific. I prefer relative ./ a directory in this directory. ../ a directory one up from this directory.
     
    Colbyt, Dec 21, 2008 IP
  3. tobydawson13

    tobydawson13 Active Member

    Messages:
    645
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #3
    That didn't really help.
     
    tobydawson13, Dec 23, 2008 IP
  4. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What do you mean by tpl files Smarty templates? If so then this should help:
    {include_php file='/path/to/load_nav.php'}
    Code (markup):
    Also check smarty documentation for more info
     
    Greg Carnegie, Dec 23, 2008 IP
  5. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #5
    What part of that did you not understand?

    I told you they have to be named .php and I showed you how to include them.
     
    Colbyt, Dec 23, 2008 IP
  6. diligenthost

    diligenthost Peon

    Messages:
    685
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This should work:
    If not, you could always create a .htaccess file in the same directory of the script you're running, asking Apache to parse PHP code in .tpl files as well. Then all you'd need is regular PHP coding (without {php} & {/php}) and it should work.
     
    diligenthost, Dec 23, 2008 IP
  7. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #7
    I think you also need to include smarty class and then copy the templates in template directory and then php fill automatically pick it up.
     
    harrisunderwork, Dec 23, 2008 IP
  8. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #8
    Guys are we even talking about smarty here?

    A lot of other developers use template files and most of them are named .tpl.
     
    Colbyt, Dec 23, 2008 IP