Wednesday, October 17, 2007

Include php file in smarty

I run a phplinkdirectory who uses smarty templates.
While I was modifying footer.tpl, I needed to include a .php file and I tried {include file="/path/to/somefile.php"} . This turned out to include it as text file, without executing it.
After some research, I found that it will execute it only if included with {include_php file="/path/to/somefile.php"}

20 comments:

  1. Hi,

    Just for information, you can also use like the following

    {php}
    include("includes/myname.php"); {/php}

    Sutha
    http://www.biznesshut.com

    ReplyDelete
  2. Thank you very much for sharing your experience. I was struggling with this for a while until I searched google and found your site.

    Thanks again.. Works like a charm

    ReplyDelete
  3. After banging my head against the monitor for several days, combing through the (sparse) smarty documentation and Googling until my fingers bled I *finally* stumbled on your note. THANKYOUTHANKYOUTHANKYOU

    Your site is at the top of MY bookmark list!

    ReplyDelete
  4. Thanks for the tips.

    I just want to add.

    that to include a variable in the parameter you need to use `

    {include_php file="`$dir_path`/my_file.php"}

    thanks.

    ReplyDelete
  5. Thanks a lot, really usefull.

    Visit my site at http://www.sistemas7g.com

    ReplyDelete
  6. This worked for me:

    {php}
    include($_SERVER['DOCUMENT_ROOT'].'/includes/file.php');
    {/php}

    ReplyDelete
  7. Just wanted to say thanks for this info, silly thin is it took me ages to find this out! :)

    ReplyDelete
  8. works perfect, BIG thanks and kisses :*

    ReplyDelete
  9. Thank you for posting this, i use this so often that i forget it every time in need it.

    so in google i type include php smarty !

    ReplyDelete
  10. Thank you very much for this snippet of code! It saved me hours of work!

    ReplyDelete
  11. Wow I knew I was missing something...

    {php} {/php}

    That's what I was looking for! Thanks for sharing. =)

    ReplyDelete
  12. thanks for the help Ana! I needed something like this for the last few months. Thanks again!

    ReplyDelete
  13. thanks SOOOO much. saved me time. :D

    ReplyDelete
  14. Thanks Ana, it is really helpful to me.

    ReplyDelete