Dealing with path differences: base directory vs. /admin/
By Paul
4/5 based on 1 vote. The median rating is 4.
By Paul
Please note that the simplest way to deal with paths is to use absolute urls. Instead of something.php link to {DIRURL}/something.php, for example -- {DIRURL} stands in for your url. The rest of this article will describe how to deal with it via relative urls, though, in case you want to.
Suppose you have your site logo in your header template as <img src="http://scripts.webmastersite.net/wsngallery/manual/mylogo.jpg">. On most of your pages this works as intended, but when you visit your admin panel or you're editing a link it becomes a broken image. This is because you've used a relative URL and there is no mylogo.jpg in the /admin subdirectory. Using an absolute URL with {DIRURL} would solve it, but may be undesirable (perhaps you want to reduce html output). For this reason, the syntax exists. Anywhere that you type , it will be replaced at viewing time by ../ if viewing in the admin directory or with nothing if viewing from the regular directory. ../ tells the browser to look one directory up. This makes the admin directory paths work the same as the regular directory paths. Thus, your header logo will work anywhere if you use this HTML:
<img src="mylogo.jpg">
There are also times when when you wish to link to something which is in the /admin/ subdirectory, but if you're writing this in the header or footer template then you don't know if the viewer is already in the /admin/ subdirectory or not. To handle this, use admin/. When in the base (non-admin) directory admin/ will become admin/, and when in the admin directory it will become blank. Thus, to link to your settings page from your header template you could use this code:
<a href="http://scripts.webmastersite.net/wsngallery/manual/admin/prefs.php">Settings</a>
This would work properly when clicked from your main directory page or from the admin panel, despite the different paths.
Suppose you have your site logo in your header template as <img src="http://scripts.webmastersite.net/wsngallery/manual/mylogo.jpg">. On most of your pages this works as intended, but when you visit your admin panel or you're editing a link it becomes a broken image. This is because you've used a relative URL and there is no mylogo.jpg in the /admin subdirectory. Using an absolute URL with {DIRURL} would solve it, but may be undesirable (perhaps you want to reduce html output). For this reason, the syntax exists. Anywhere that you type , it will be replaced at viewing time by ../ if viewing in the admin directory or with nothing if viewing from the regular directory. ../ tells the browser to look one directory up. This makes the admin directory paths work the same as the regular directory paths. Thus, your header logo will work anywhere if you use this HTML:
<img src="mylogo.jpg">
There are also times when when you wish to link to something which is in the /admin/ subdirectory, but if you're writing this in the header or footer template then you don't know if the viewer is already in the /admin/ subdirectory or not. To handle this, use admin/. When in the base (non-admin) directory admin/ will become admin/, and when in the admin directory it will become blank. Thus, to link to your settings page from your header template you could use this code:
<a href="http://scripts.webmastersite.net/wsngallery/manual/admin/prefs.php">Settings</a>
This would work properly when clicked from your main directory page or from the admin panel, despite the different paths.
Rating:
4/5 based on 1 vote. The median rating is 4.
Submitted: 11/04/03 (Edited 08/27/07)
Description: Effectively write your templates to look the same whether viewed from your base directory or from the admin directory.
Views:
1608 views. Averaging 1 per day.
In the most recent 30 day period, there've been 0 views.

Print
E-Mail