|
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 |
hughprior Smarty Rookie
Joined: 07 May 2003 Posts: 10
|
Posted: Tue Sep 14, 2004 9:41 am Post subject: Problem with relative paths finding templates |
|
|
I have a problem getting the relative paths working on my actual website (www.localpin.com), though everything works fine when I run things locally (localhost).
Compare the following 2 identical files in different directories:
http://www.localpin.com/testdb.php (it finds the template - ignore the other errors!)
http://www.localpin.com/main/maintestdb.php (it doesn't find the template)
I have put my templates in a directory off the root, i.e. in a directory /smartyplates/.
Rather than put the template information in the Smarty class, or define it each time I want to use a template, I have created a class SmartyPin in which I set the Smarty "templates" variable, and I always declare an object of type SmartyPin.
Now, what should the assignment of the template variable look like?
Amongst others, I have tried:
$template = "/smartyplates"
$template = "smartyplates"
Thanks for any help. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Sep 14, 2004 5:07 pm Post subject: |
|
|
I suggest you calculate your absolute base path during your initialization and then prepend that to your smarty directory assignments. For example, if you are using a prepend script that exists in your root dir and contains something like the following:
[php:1:d209fc9526]<?php
list($root_drive, $root_path) = explode(':', __FILE__);
if ($root_path) {
$root_drive .= ':';
$root_path = dirname($root_path);
} else {
$root_path = dirname($root_drive);
$root_drive = '';
}
define ('MY_ROOT_DRIVE', $root_drive);
define ('ROOT_DIR', MY_ROOT_DRIVE.$root_path.DIRECTORY_SEPARATOR);
?>[/php:1:d209fc9526]
Then you can use an absolute path which is what I would recommend. EG:
$template = ROOT_DIR."smartyplates"
Just a note: I haven't tested that code too heavily but it is supposed to work on both *nix and win. It is working for me, but YMMV
There are alternates to this strategy in this thread: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1268
HTH |
|
Back to top |
|
hughprior Smarty Rookie
Joined: 07 May 2003 Posts: 10
|
Posted: Tue Sep 21, 2004 4:44 pm Post subject: |
|
|
Yes, that did a great job. Not sure I understood how that code snippet works and the zillion things I tried didn't, but one day when it breaks I guess I'll have to...
Anyway, thanks for the quick response. |
|
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
|