...

Subimbedded statement for relative path

welo
07-27-2002, 07:57 PM
I'm using a statement to write repetitive code in an include

<?php $repeat="table blah blah blah">

Within this table is a td needing a background image, while the page writing the include contains a statement for the image path. f.ex.:

<td style=\"background-image: url (images/button.jpg)\"> would need to be ../images/button.jpg if it is in a subdir, so index.php would have something like:

$imgpath="../";

While the include would normally contain something like:

(<?=$imgpath;?>images/button.jpg)

However:

<?php $repeat="<td style=\"background-image: url(<?=$imgpath?>images/button.jpg)\";?>

isn't going to work in this case, so what am I neglecting to do? It's gotta be something really simple.

Thanks in advance.

Spookster
07-28-2002, 05:14 AM
So let me get this straight. You have an image in an include file and you want to use a relative path for the image no matter what page/directory the include get put into?

firepages
07-28-2002, 09:31 AM
Originally posted by Spookster
So let me get this straight. You have an image in an include file and you want to use a relative path for the image no matter what page/directory the include get put into?

..which is, as I am assuming Spookster means, not really a good idea (& certainly not worth the hassle ?)

just define the image path ina general include or header page, the speed difference is probably not measurable

define('IMG_PATH','/home/www/path/images/')

and use (<?=IMG_PATH;?>images/button.jpg)

or plain ol $_SERVER[DOCUMENT_ROOT].'/images/'; (wont work with script-aliased directories!)


I have done similar things before and set the relative $ROOT in a variable on several calling pages but it gets messy!

welo
07-28-2002, 10:38 AM
Originally posted by firepages


..which is, as I am assuming Spookster means, not really a good idea (& certainly not worth the hassle ?)

I see what you're saying, though in this case I have little choice since I'm developing the site on one server to install to another, and the only way to make it match is by using relative paths. On top of this, even though I have root access to the second server, this is a facelift for an existing site being built in a clean directory and will be launched all at once by re-pointing IPs. Otherwise I'd just use an absolute path in my css for the background image and define it as a class (which requires far less code).

I hadn't thought of using a literal server path for the images though (never needed to do that before). That could be the ticket. Thanks for pointing it out. :)

welo
07-29-2002, 06:58 PM
This doesn't work, because the solution you suggest repeats my original problem. :( Here's why:

I start with a table that acts as a button:

<table border="0" cellpadding="0" cellspacing="2">
<tr height="26">
<td style="background:url(path/to/button.jpg)" height="26" width="130">
<a href="index.php" class="menu">Homepage</a>
</td>
</tr>
</table>

This table is in an include such as menu.inc, and occupying this include are maybe 15 of these buttons. To eliminate the redundant html, I do something like:

$repeat="<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\">

and the same for <tr> and <td> etc. until I reach my href, then conlude the statement with another string:

$end="</a></td></tr></table>";

In this manner the code for every button is written as:

<?=$repeat?>index.php">Homepage<?=$end?>

Isn't this much prettier? :D

So the question is, what do I use to replace:

background:url(path/to/button.jpg)

so it won't conflict with my $repeat string and is still recognized? Sorry if I'm explaining this incorrectly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum