Php in smarty

Discussion in 'PHP' started by pitttih, Feb 22, 2008.

Thread Status:
Not open for further replies.
  1. #1
    hey there.
    how can i include an external php scripts ( with +10 php files ) in smarty template engine ?

    i know that i can use {php} include("blah.php"); {/php} but there are many other files included in blah.php itself..
    and smarty Can't load them.

    what is the easiest way to do that?

    thanks:D
     
    pitttih, Feb 22, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    The PHP code should be separated from the Smarty logic. You shouldn't do it the way you're trying to do it...

    Use Smarty includes {include file="file.tpl"} - And make sure you edit your "blah.php" file to work with Smarty.
     
    nico_swd, Feb 22, 2008 IP
  3. pitttih

    pitttih Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can you explain me little bit more ? what should i include in file.tpl for example?
    Pm me on msn if its possible i need this badly :(
     
    pitttih, Feb 22, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Sorry, I don't give private support over MSN or PM.

    As for the question, I can't answer it properly without seeing the content. The PHP code should be in the .php files. And the whole layout should go in the .tpl file.

    I suggest you should not use Smarty if you don't know its purpose. (No offence). But you should check their website to read about it. http://smarty.php.net
     
    nico_swd, Feb 22, 2008 IP
  5. NathanH

    NathanH Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I agree with nico_swd. If you don't know the real purpose of Smarty, I don't suggest that you use it. You should not have any PHP in the tpl files (It pretty much defeats the purpose).
     
    NathanH, Feb 22, 2008 IP
  6. KnuTz

    KnuTz Well-Known Member

    Messages:
    169
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #6
    why bother using a template engine if your just goin to put external code into it^^
     
    KnuTz, Feb 22, 2008 IP
  7. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The basic flow for Smarty (or any template engine - or really just any good separation of logic/output) is that you do all your logic and processing in one place and then store all the info you need for output into variables which you pass to the template. The template does no logic just output processing. So if you're trying to put any database/file access or business logic into your template you're doing it wrong.

    One kind of sticking point for people new to templating is that there is some display logic in the template. Things like looping over an array to output a number of rows in a table or things like "only display this link if they're logged in" are part of the display logic and properly belong in the template.
     
    jnestor, Feb 22, 2008 IP
Thread Status:
Not open for further replies.