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

Loading plugins... Happy plugin directory guessing

 
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 3
View previous topic :: View next topic  
Author Message
yankee
Smarty Rookie


Joined: 02 Mar 2009
Posts: 31

PostPosted: Sun Mar 08, 2009 10:10 am    Post subject: Loading plugins... Happy plugin directory guessing Reply with quote

I just tried to use a modifier which did not work "unknown modifier..."

I noticed that smarty loads its plugins from the directory ./plugins which is relative to its current working directory.
Thus loading plugins will fail if the cwd is != smarty's root directory.
This will fix the problem:
Code:
Index: Smarty3Alpha/libs/Smarty.class.php
===================================================================
--- Smarty3Alpha/libs/Smarty.class.php  (revision 3024)
+++ Smarty3Alpha/libs/Smarty.class.php  (working copy)
@@ -165,7 +165,7 @@
         // set default dirs
         $this->template_dir = '.' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
         $this->compile_dir = '.' . DIRECTORY_SEPARATOR . 'templates_c' . DIRECTORY_SEPARATOR;
-        $this->plugins_dir = array('.' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR);
+        $this->plugins_dir = array(dirname(__FILE__). DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR);
         $this->cache_dir = '.' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
         $this->config_dir = '.' . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR;
         $this->sysplugins_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysplugins' . DIRECTORY_SEPARATOR;
(You might want to check whether the same problem applies to the "config" dir...)
BTW: Using the DIRECTORY_SEPARATOR constant is not necessary. You can always use a slash (/). PHP handles this correctly on any platform!
Replacing the constant with just a slash could make the code easier to read and it will increase the performance a tiny bit.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun Mar 08, 2009 10:35 am    Post subject: Reply with quote

Will be fixed with the next SVN update.

The default plugins_dir will be relative to the Smarty root not the working directory.

Thanks for your input.
Back to top
View user's profile Send private message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Wed Oct 14, 2009 6:05 pm    Post subject: 3 kinds of smarty plugins stored in different locations Reply with quote

Using DIRECTORY_SEPARATOR anywhere is not necessary. PHP is generous, and works in Windows as well.

Plus, here is my idea on implementing various kinds of plugins into different locations. I use to put them in separate folders, and configure the Smarty as:
Code:
$smarty->plugins_dir[]    = __ROOT__.'/smarty_plugins/common';
$smarty->plugins_dir[]    = __ROOT__.'/smarty_plugins/specific';


Make sure that:
You have not missed square brackets around the variable ( [ ] ).
You have made smarty_plugins/common, and smarty_plugins/specific in the root of the website.
Define __ROOT__ as the root of your website, earlier than configuring Smarty, as absolute path name.

Smarty’s default plugin folder holds the plugins shipped by default.
Now, smarty_plugins/common holds the plugins that are reusable over many projects. Examples include numner to word conversion, reading css and javascripts, url shortening, linking to wiki pages, weight conversion, date calculator etc.
Smarty_plugins/specific holds the plugins that are needed only for the current project, and not usable to others.

So, in total, we have three different kinds of plugins organized in various locations, for clarity.
Back to top
View user's profile Send private message Visit poster's website
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 3 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