|
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 |
tomekStg Smarty n00b
Joined: 04 Feb 2010 Posts: 1
|
Posted: Thu Feb 04, 2010 7:42 am Post subject: Prepare Smarty to load by AJAX |
|
|
Assume we have a php file located:
/path/to/www/ajax_server/file.php
and template file located:
/path/to/www/ajax_server/templates/file.tpl
As far as we want only load
/path/to/www/ajax_server/file.php which calls internally
$smarty->display('file.tpl')
everything is OK and file is shown properly
but if we want
/path/to/www/ajax_server/file.php
to be loaded by ajax from other location for example:
/path/to/www/ajax_client/client.html
something is wrong.
The reason is that smarty is looking for template directory relatively from location where is loaded:
/path/to/www/ajax_client/templates
and doesn't find.
I solved it so:
opened Smarty.class.php to edit
and edited Smarty constructor as follows:
function Smarty($file = null)
and added to contructor body following code
if(!empty($file))
{
$this->template_dir = dirname($file)."/templates/";
$this->compile_dir = dirname($file)."/templates_c/";
$this->config_dir = dirname($file)."/configs/";
$this->cache_dir = dirname($file)."/cache/";
}
Now everytime i Plan my php to be loaded by Ajax I call constructor with
__FILE__ parameter.
It simply sets templates etc paths as fixed depending on where php is located. |
|
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
|