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

Open the view in a folder

 
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
gremio10
Smarty Rookie


Joined: 28 Jan 2011
Posts: 11

PostPosted: Thu Aug 25, 2011 8:48 pm    Post subject: Open the view in a folder Reply with quote

Hey!, I have my folder views that have all my .tpl, but I want to separate some of my .tpl, so I created another folder, called pro, and I put my .tpl inside, and in my PHP i put ->display( "pro/questions.tpl" ); but it returns this error:

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'questions.tpl'' in C:\xampp\htdocs\ligadedoutores\Smarty\libs\sysplugins\smarty_internal_template.php:163 Stack trace: #0 C:\xampp\htdocs\ligadedoutores\Smarty\libs\sysplugins\smarty_internal_template.php(550): Smarty_Internal_Template->isExisting(true) #1 C:\xampp\htdocs\ligadedoutores\Smarty\libs\Smarty.class.php(338): Smarty_Internal_Template->getRenderedTemplate() #2 C:\xampp\htdocs\ligadedoutores\Smarty\libs\Smarty.class.php(382): Smarty->fetch('questions.tpl', NULL, NULL, NULL, true) #3 C:\xampp\htdocs\ligadedoutores\pro\questions.php(11): Smarty->display('questions.tpl') #4 {main} thrown

Thank you
Back to top
View user's profile Send private message Send e-mail
androidworkz
Smarty Rookie


Joined: 08 Aug 2011
Posts: 15

PostPosted: Tue Sep 13, 2011 7:25 pm    Post subject: Reply with quote

Two issues here... first, I think you have to pass the absolute path. How I accomplished this was to create a class that extends smarty and my own "display" method that returns the full path. Kind of like this



Code:

// this is a very simple example.

class View extends Smarty {
    public function __construct($cfg = array()) {
        parent::__construct();
       
        $this->template_dir = $cfg['template_dir'];
        $this->compile_dir  = $cfg['compile_dir'];
        $this->config_dir   = $cfg['config_dir'];
        $this->cache_dir    = $cfg['cache_dir'];
    }

    public function load($template) {
        $this->display($this->template_dir.$template);
    }
}


The second issue is the DIRECTORY_SEPARATOR constant. Since you are developing on a Windows machine you should use it.
Back to top
View user's profile Send private message
seikialice88
Smarty n00b


Joined: 22 Nov 2011
Posts: 1

PostPosted: Wed Nov 23, 2011 1:57 am    Post subject: Re: Open the view in a folder Reply with quote

gremio10 wrote:
Hey!, I have my folder views that have all my .tpl, but I want to separate some of my .tpl, so I created another folder, called pro, and I put my .tpl inside, and in my PHP i put ->display( "pro/questions.tpl" ); but it returns this error:

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'questions.tpl'' in C:\xampp\htdocs\ligadedoutores\Smarty\libs\sysplugins\smarty_internal_template.php:163 Stack trace: #0 C:\xampp\htdocs\ligadedoutores\Smarty\libs\sysplugins\smarty_internal_template.php(550): Smarty_Internal_Template->isExisting(true) #1 C:\xampp\htdocs\ligadedoutores\Smarty\libs\Smarty.class.php(338): Smarty_Internal_Template->getRenderedTemplate() #2 C:\xampp\htdocs\ligadedoutores\Smarty\libs\Smarty.class.php(382): Smarty->fetch('questions.tpl', NULL, NULL, NULL, true) #3 C:\xampp\htdocs\ligadedoutores\pro\questions.php(11): Smarty->display('questions.tpl') #4 {main} thrown

Thank you

Thanks you for the post.
__________________
Watch Hugo Online Free
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