Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Can't resolve me error

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
mise
Smarty n00b


Joined: 01 Dec 2011
Posts: 2

PostPosted: Thu Dec 01, 2011 8:47 pm    Post subject: Can't resolve me error Reply with quote

Hi,

I'm getting a common error (from what I've seen on the forums):

Quote:
Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'index.tpl'' in /usr/local/lib/php/Smarty/sysplugins/smarty_internal_templatebase.php:141
Stack trace:
#0 /usr/local/lib/php/Smarty/sysplugins/smarty_internal_templatebase.php(376): Smarty_Internal_TemplateBase->fetch('index.tpl', NULL, NULL, NULL, true)
#1 [censored]/SmartyBite.class.php(86): Smarty_Internal_TemplateBase->display('index.tpl', NULL, NULL, NULL)
#2 [censored]/index.php(34): SmartyBite->display('index.tpl')
#3 {main}
thrown in /usr/local/lib/php/Smarty/sysplugins/smarty_internal_templatebase.php on line 141


From what I've read, this could be:
* The file isn't readable.
* The path is set incorrectly.

I think the file is readable. I committed sacrilege, and edited smarty_internal_templatebase.php to test it out.

The following code, in Smarty's `fetch` function does output the raw contents of the template file:

Code:
$handle = @fopen($this->template_dir.'/'.$_template->source->name, "r");
while (($buffer = fgets($handle, 4096)) !== false) {
    echo $buffer;
}


I suspect the problem is that I have my own custom code, something as follows:
Code:
class SmartyBite extends Smarty {
   var $set;

   public function __construct() {
      parent::__construct();
      $this->set = new Settings();
      if (!defined('MY_DIR'))   {
         define ("MY_DIR", $this->setting('path.smarty_templates'));
      }
      /**
       * Set up some Smarty options.
       */
      $this->compile_check = true;
      $this->debugging = true;
      $this->template_dir = MY_DIR.'templates';
      $this->compile_dir = MY_DIR.'compiled_templates';
      $this->cache_dir = MY_DIR.'cached_templates';
      $this->config_dir = MY_DIR.'configs';
      $this->cache_lifetime =  86400; // One day. 60*60*24
      $this->assign('s', $this);
   }
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Dec 01, 2011 9:18 pm    Post subject: Reply with quote

If you are using Smarty 3.x, use the setters/getters.

$smarty->setTemplateDir('...');

same for config dir, cache dir, compile dir.

Also to test your file, you can probably just try:

echo file_get_contents($smarty->getTemplateDir() . '/index.tpl');
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Dec 01, 2011 9:28 pm    Post subject: Reply with quote

See http://www.smarty.net/docs/en/installing.smarty.extended.tpl example 2.10
Back to top
View user's profile Send private message
mise
Smarty n00b


Joined: 01 Dec 2011
Posts: 2

PostPosted: Fri Dec 02, 2011 7:48 am    Post subject: Reply with quote

Yes, I'm on Smarty 3 (for the past few months), and using `$smarty->setTemplateDir('...');` now works.

I had failed to notice this change when updating Smarty, I guess.

Glad I asked here, thank you so much! Cool
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP