SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Template image path

    How would you set the image path when including templates? The goal is to allow the designer to open the html template, make their edits and save and the php code would bring it in and display it. The problem is images, take this html template:

    template/template.html
    Code:
    <html>
    <head></head>
    <body>
    Hi there! <img border="0" src="../images/smiley.gif">
    </body>
    </html>
    Now bringing up the html template in an html editor shows the image correctly but bringing it into the root of the folder in php shows a broken image:

    /index.php
    /images/
    PHP Code:
    include('template/template.html'); 
    Well the image folder is in the root of the php file so the image path is invalid. I cant have the editors use the full url path because the domain might be different. Do I have to write a script that rewrites all relative paths with the absolute path when building the template on the php side?

    Silly

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    http://example.com/image/folder/image.ext

    can be rewritten as /image/folder/image.ext

    I always use root relative paths always.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    http://example.com/image/folder/image.ext

    can be rewritten as /image/folder/image.ext

    I always use root relative paths always.
    So your saying that if a designer wanted to add an image to template.html through Frontpage they would need to add the image and then turn the relative path to the root relative path in the html code itself correct? Because normally in a WYSIWYG if I added an image from the image folder it would look like:

    Code:
    <img border="0" src="images/someimage.gif">
    What your saying is the designer would need to manually change the code to look like:

    Code:
    <img border="0" src="/templates/images/someimage.gif">
    Correct?

    Silly

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Yes. if you did relative to the file thats in the template folder but you are including it in index.php outside of the template folder those path no longer work.

    Also what happens when you want to use the same template seven folders up? http://example.com/f1/f2/f3/f4/f5/f6/f7/file.ext but with root relative urls for paths. /templates/images/someimage.gif goes straight to the file.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •