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:

Delta Systems said...

perfect! thanks!

Anonymous said...

Hi,

Just for information, you can also use like the following

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

Sutha
http://www.biznesshut.com

Anonymous said...

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

Anonymous said...

Cool thanks

Anonymous said...

Thank you!

Anonymous said...

Another thanks!

Anonymous said...

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!

Unknown said...

You rock, works great.

Anonymous said...

good one

Anonymous said...

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.

Noticias de Rosario said...

Thanks a lot, really usefull.

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

JohnVt said...

This worked for me:

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

Unknown said...

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

Anonymous said...

works perfect, BIG thanks and kisses :*

vincent said...

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 !

Dave said...

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

Laser Toner Dave said...

Wow I knew I was missing something...

{php} {/php}

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

SOLID said...

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

Soda Kia said...

thanks SOOOO much. saved me time. :D

shraddha said...

Thanks Ana, it is really helpful to me.