http://qs321.pair.com?node_id=678589


in reply to Question about web trees, html paths, and HTML::Template

I'm not sure what's going on in your second case, i.e. "If I move the /images under /admin (see below), no joy", but the first case the missing image is entirely to be expected.

If your template contains

<img src="images/save_btn.gif" />
and you use that template to render a page at the URL
http://www.domain1.com/admin/
then, no, the image isn't "there", because "there", in that case, is the admin folder, and the path you're telling the browser to look at is
admin/images/
and it isn't there.

You need to stop thinking about the location of the HTML::Template files. It makes no difference to the output. It doesn't matter where they are. They could be 47 folder levels down, or on another part of the filesystem altogether for all the browser cares.

Instead, think about it from the browser's point of view. All the browser knows is that it's been given some HTML, at an admin folder URL, and told there's an image one folder down. And there isn't.

What I would do is always use root-relative paths.

If your images are in domain.name.com/foo/images/, then make all references to the begin with a leading slash:

<img src="/foo/images/save_btn.gif" />
it's easy to remember, gives you a consistent policy for both software and people to work with, and solves problems moving your code from one server to another.


Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...