6

SOLVED: Error in template file

I have Smarty setup like this:

require_once 'smarty/Smarty.class.php';
$smarty = new Smarty();

$smarty->compile_dir = $compile_dir;
$smarty->template_dir = $tpl_dir;

That's all I should need for now... I have Smarty setup exactly like this for another site and it works just fine on the same server.

var_dump($smarty) outputs all its public variables and $smarty->template_exists("index.tpl") returns 1, which would both indicate that Smarty is properly setup and working, however, both $smarty->display("index.tpl") and $output = $smarty->fetch("index.tpl"); echo $output; outputs blank page. And the index.tpl file certainly contains HTML.

Have I forgotten some step or what?

Edit:

Added

ini_set('display_errors', true);
error_reporting(E_ALL + E_NOTICE);

Also created config directory for Smarty.

And tried $output = $smarty->fetch("index.tpl"); var_dump($output).

Still blank page.

If I echo "foo"; before $smarty->display("index.tpl") it outputs the line, but if I do it after it, it doesn't output it.

TheMagician
  • 1,846
  • 7
  • 20
  • 26

4 Answers4

11

Change the permission of templates_c directory.

Sunil Mishra
  • 3,796
  • 1
  • 27
  • 40
4

Give folder permission to folder smarty/template_c.

I using Mac so follow this steps:

  • Open Terminal

  • Go to htdocs folder

  • Go to project

  • Go to Smarty lib

  • Use command

     "chmod -R 0777 template_c"
    

My project is exists on the folder

    naveenos-MacBook-Pro:smarty nos$ chmod -R 0777 /Application/XAMPP/htdocs/smartyProject/lib/smarty/templates_c/

That's it.

Community
  • 1
  • 1
naveenos
  • 408
  • 1
  • 4
  • 7
1

Try adding error checking to you page

ini_set('display_errors', true);
error_reporting(E_ALL + E_NOTICE);

If that gets you nothing, I would try setting the $smarty->config_dir and $smarty->cache_dir attributes. They might be needed.

And, of course, make sure the file permissions for all the directories are valid, and that SAFE_MODE is off. (That can mess Smarty up in very odd ways.)

Atli
  • 7,855
  • 2
  • 30
  • 43
1

I had additional {foo.bar} (without $) variables in the template file that were supposed to be implemented later in the code, assuming Smarty would just replace those with blank I didn't think it could be those causing the problem, but after removing them it worked fine.

TheMagician
  • 1,846
  • 7
  • 20
  • 26
  • Thank you for this answer. I had a similar issue. Turned out that the template contained something like `{$foo="$obj->value"}`. Turned out that interpolating this did not work – Rik Sep 21 '21 at 09:28
  • Turned out that interpolating this did not work.Removing the quortes fixed the issue – Rik Sep 21 '21 at 09:42