Include PHP-file in Smarty

I’m teaching myself PHP and Smarty these days, and today I ran across a common problem:

«How do I include a PHP-file – or execute PHP-code – when using the Smarty template engine?»

After banging my head against the wall for a couple of hours, I finally found the solution. To include a PHP-file in a Smarty template, use the following code:

{include_php file=”/path/to/somefile.php”}

You can also use the following code to run and/or execute PHP-code within Smarty:


Hope this blog post helps some poor soul one day… Keep hacking.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s