Erling Løken Andersen's blog

A blog by Erling Løken Andersen on random entrepreneurial topics.

  • 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:

    {php}
    include(“includes/myname.php”);
    {/php}

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