Orange Lux
Orange Lux

Reputation: 1987

Smarty - change cache directory

I'm using Smarty for a website, but I'm annoyed I have to declare the templates dir, the cache dir and the compile dir every time I initiate Smarty, like so :

$smarty = new Smarty();
$smarty->setCacheDir(__DIR__ . '/cache/smarty/');
$smarty->setCompileDir(__DIR__ . '/cache/smarty_c/');
$smarty->setTemplateDir(__DIR__ . '/templates/');

Is there a way (By defining variables in my configuration file which is loaded on every page, for instance), to tell Smarty once and for all which are these directories, so I don't have to tell it every time?

Upvotes: 1

Views: 729

Answers (1)

Orange Lux
Orange Lux

Reputation: 1987

I somewhat solved the issue by creating a new class which extended the Smarty class, but I'm still open to new kind of answers.

class MySmarty extends Smarty
{
    const SMARTY_TEMPLATES = __DIR__ . '/../templates/';
    const SMARTY_COMPILED  = __DIR__ . '/../cache/smarty_c/';
    const SMARTY_CACHE     = __DIR__ . '/../cache/smarty/';

    public function __construct()
    {
        $this->setTemplateDir(self::SMARTY_TEMPLATES);
        $this->setCompileDir(self::SMARTY_COMPILED);
        $this->setCacheDir(self::SMARTY_CACHE);
        parent::__construct();
    }
}

Upvotes: 1

Related Questions