0
votes

Trying to use Smarty properly, I created a config file. The file structure is like this:

/Smarty/
/Smarty/cache
/Smarty/configs
/Smarty/configs/main.conf
/Smarty/plugins
/Smarty/sysplugins
/Smarty/templates_c
/templates/
/templates/main.tpl
index.php

In main.tpl I try to load the main.conf from /Smarty/configs/main.conf by: {config_load "main.conf"} as explained here: http://www.smarty.net/docs/en/language.config.variables.tpl This doesn't work ("Fatal error: Uncaught exception 'SmartyException' with message 'Unable to read config file 'main.conf'' in..."), however this does work:

{config_load "/var/www/vhosts/*domain*/subdomains/cms/httpdocs/Smarty/configs/main.conf"}

Why doesn't the first example work? I did set the config dir earlier by:

$smarty->setConfigDir(SMARTY_DIR.'configs/');

But the config dir isn't found. Could someone please help me? Thanks in advance!

2
Print $smarty->getConfigDir() after you call setConfigDir to see what path is actually there. - Eugene
@Eugene The path seems to be correct. It print_rs: "Array ( [0] => /var/www/vhosts/*domain*/subdomains/cms/httpdocs/Smarty/configs/ )" - Blee
Can you check the file for permissions? Maybe the file does not have read permission. - Karan Punamiya
@KaranPunamiya Set configs and main.conf to 777 for the occasion, but didn't change the errors.. - Blee

2 Answers

1
votes

i got same problem, i have smarty integrate in CodeIgniter. and this is what i did
1) $this->smarty->addConfigDir('YourPath');
in your case may become $smarty->addConfigDir('YourPath');

then print var_dump($this->smarty->getConfigDir()); in the browser.
in your case may become var_dump($smarty->getConfigDir());

2) after that you may change $this->smarty->setConfigDir('YourPath'); in your case may become $smarty->setConfigDir('YourPath');
it works in my case.

0
votes

here is sample of the config i use and it's working fine with me

/////Smarty including
require_once('libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'template'; // template folder
$smarty->compile_dir = 'cache'; // Create a Folder Cache with 777 Permission

This Settings works fine with latest smarty edition Smarty 3.x.