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

Problem with relative paths finding templates

 
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 -> Installation and Setup
View previous topic :: View next topic  
Author Message
hughprior
Smarty Rookie


Joined: 07 May 2003
Posts: 10

PostPosted: Tue Sep 14, 2004 9:41 am    Post subject: Problem with relative paths finding templates Reply with quote

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
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Sep 14, 2004 5:07 pm    Post subject: Reply with quote

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 Smile

There are alternates to this strategy in this thread: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1268

HTH
Back to top
View user's profile Send private message
hughprior
Smarty Rookie


Joined: 07 May 2003
Posts: 10

PostPosted: Tue Sep 21, 2004 4:44 pm    Post subject: Reply with quote

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... Wink

Anyway, thanks for the quick response.
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 -> Installation and Setup 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