0

I've added an image to a block that shows on every page and have the image added manually in the block like so:

<img src="sites/default/files/image-name" />

It shows fine on the home page as intended, but on the interior pages it doesn't show. I inspected element and for most pages it's using the same URL to try and access it.

I cleared cache.

Thoughts on why this might be?

3
  • That's how HTML work. You hardcoded it as a relative link, so if it appears on example.com/somearticle, browsers are obligated to look for image at example.com/somearticle/sites/default/files/image-name - and this path does not exist.
    – Mołot
    Commented Oct 28, 2015 at 7:18
  • @Molot right...but, I thought in Drupal this always worked. Well, I guess I just have to make it absolute then. Thanks for the follow-up.
    – Sage
    Commented Oct 28, 2015 at 7:25
  • Drupal is just a glorified HTML generator. At the end of the day, html will work like html always does. image_style_url is a Drupal way around this particular problem
    – Mołot
    Commented Oct 28, 2015 at 8:29

3 Answers 3

3
<img src="sites/default/files/image-name" />

right now its appending after the url of whatever page you are on.

yourwebsite.com/hello/sites/default/files/image-name
yourwebsite.com/article/sites/default/files/image-name
yourwebsite.com/contact-us/sites/default/files/image-name

instead of appending after your domain name.

yourwebsite.com/sites/default/files/image-name

so you just need to add a / at the beginning, so it appends after your domain name only.

so your code needs to be:

<img src="/sites/default/files/image-name" />
5
  • yes, that's what I was looking for!
    – Sage
    Commented Oct 28, 2015 at 21:19
  • ok, so I thought that's what was needed and I'm pretty sure that's what I've done before. But when I put my links in like this the image placeholder shows up and not the image on every page. Any idea why that might be?
    – Sage
    Commented Oct 28, 2015 at 23:14
  • Nevermind i fixed it. it's because the whole site is in a sub-directory and i need to reference that ALSO, like so: /sub-dir/sites/etc.
    – Sage
    Commented Oct 28, 2015 at 23:15
  • you shouldn't need to ref your sub directory. Did you setup your 000-default.conf correctly? see my answ in Error Finding Home page for Drupal 7 Site on Ubuntu Linux I put my site inside a folder called Drupal.
    – No Sssweat
    Commented Oct 28, 2015 at 23:28
  • thanks for the follow-up. I setup my site in /var/www/sitename which is why I guess I have to reference it in my links now. But I think I see what you mean. I could just put that whole path in my 000-default.conf and add additional sites also. I'll just try that. Thanks for clarifying!
    – Sage
    Commented Oct 29, 2015 at 6:23
1

Please check if the block has permission to display content with internal pages also like block display might have been set as the only.

2
  • thank you, it does. I just went ahead and made the links absolute and that fixed the problem.
    – Sage
    Commented Oct 28, 2015 at 18:30
  • absolute links are sometime so much pain in the ass especially when you move your site to different server. All your links need to be updated so I suggest use relative links
    – Shabir A.
    Commented Oct 28, 2015 at 21:21
1

If all you want to have image in block you can use image block module. Its pretty easy to use.

1
  • thank you that's also a good idea I had not considered. What I was looking for specifically is above.
    – Sage
    Commented Oct 28, 2015 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.