Jump to content

Template system


NLT

Recommended Posts

I've created a template system.

 

I've got a function to assign a page (the templates are in /template/skin).

It all works fine in the main root, but if I had a directory it won't work.

 

$dir = "template/skin";

That is found in template/

 

I need to be able to assign the template even in directories.

Link to comment
Share on other sites

Try defining the path from the root of the site by including a forward slash at the beginning. Otherwise, without it, you are defining it relative from the current working directory.

$dir = "/template/skin";

Warning: file_get_contents(/template/skin/404.tpl) [function.file-get-contents]: failed to open stream: No such file or directory

 

Although if I type /template/skin/404.tpl with the document I'm on (no index.php etc) then it downloads a tpl file.

Link to comment
Share on other sites

You never stated you were using file_get_contents()! That would use the file system directory structure and not the web directory structure. I don't know why you would be using file_get_contents() instead of an include() anyway.

Link to comment
Share on other sites

As stated, file_get_contents() is based upon the file system directory, not the web directory. I would suggest using a config file that is loaded on every page that includes a variable to the location of the templates folder.

Link to comment
Share on other sites

Would something like this work in configuration.php (as it's called every file, and in root):

$template->SetDir("/template/skin");

and then in the template:

public $dir; 
function SetDir($dir)
{
   $this->dir = $dir;
}

 

Then replace everything with that?

Link to comment
Share on other sites

As I said, that path is a relative path. That means it is relative from the current working directory. The workign directory is different based upon which file is being run. You need the path to be hard coded from the root of the file path, e.g. c:\some_directory\another_directory\. But, if you are on a shared host, I have no idea what it would look like.

Link to comment
Share on other sites

But, if you are on a shared host, I have no idea what it would look like.

One quick way to find out is when you have error reporting on and try to include a file that doesn't exist, it will tell you where it tried to look. There's your path.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.