|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
yankee Smarty Rookie
Joined: 02 Mar 2009 Posts: 31
|
Posted: Sun Mar 08, 2009 10:10 am Post subject: Loading plugins... Happy plugin directory guessing |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Mar 08, 2009 10:35 am Post subject: |
|
|
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 |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Wed Oct 14, 2009 6:05 pm Post subject: 3 kinds of smarty plugins stored in different locations |
|
|
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 |
|
|
|
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
|