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

Configurable Smarty work dir

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
martiendejong
Smarty n00b


Joined: 17 Dec 2011
Posts: 2

PostPosted: Sat Dec 17, 2011 9:42 pm    Post subject: Configurable Smarty work dir Reply with quote

Hi all!

I must say I'm relatively new to Smarty since I just installed.
But I came across an issue that may be of interest to you guys as well.

When I was installing I noticed that Smarty has its workdir as '.' by default, and this is not configurable (without changing the code).

I would like to have my configuration setup in such a way that I use a separate folder out of my www folder for all Smarty related files.

So this is my structure:

var
..mysite
....www
......home.php
....app
......include
........smarty
..........Smarty.class.php
......smarty
........templates
........templates_c
........cache

My proposal is to add a constant called SMARTY_WORKDIR which is by default set to '.', and use it in the constructor instead of '.'.
This way people can set their Smarty work dir by overriding this variable.



TL;DR

When I was installing I noticed that Smarty has its workdir as '.' by default, and this is not configurable.

Solution: Add the constant SMARTY_WORKDIR:

in Smarty.class.php line 0:
Code:
if (!defined('SMARTY_WORKDIR')) {
    define('SMARTY_WORKDIR', '.' . DS);
}


in Smarty.class.php line 595:
Code:
$this->setTemplateDir(SMARTY_WORKDIR . DS . 'templates' . DS)
       ->setCompileDir(SMARTY_WORKDIR . DS . 'templates_c' . DS)
       ->setPluginsDir(SMARTY_PLUGINS_DIR)
       ->setCacheDir(SMARTY_WORKDIR . DS . 'cache' . DS)
       ->setConfigDir(SMARTY_WORKDIR . DS . 'configs' . DS);
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat Dec 17, 2011 11:37 pm    Post subject: Reply with quote

It's not necessary to modiy the code.

Just call
Code:
$smary->setTemplateDir(SMARTY_WORKDIR . DS . 'templates' . DS)
       ->setCompileDir(SMARTY_WORKDIR . DS . 'templates_c' . DS)
       ->setPluginsDir(SMARTY_PLUGINS_DIR)
       ->setCacheDir(SMARTY_WORKDIR . DS . 'cache' . DS)
       ->setConfigDir(SMARTY_WORKDIR . DS . 'configs' . DS);


After you have created the $smarty object.
Back to top
View user's profile Send private message
martiendejong
Smarty n00b


Joined: 17 Dec 2011
Posts: 2

PostPosted: Sun Dec 18, 2011 1:17 pm    Post subject: Reply with quote

Ok, that's a good solution too. Thanks for bringing that up!
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 -> Feature Requests 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