0

I am recreating an existing website and part of the process is enabling a theme from the same existing site on my new version.

The theme is called microsite and has an image located in /microsite/images/.

In the original site, the image from the above directory is loaded and displayed in a block. I copied the code from the block of the original site, pasted and saved in a block of my new site. The code is as follows:

<a href="/publications" target="_self">
  <img src="/sites/all/themes/microsite/images/image.jpg" />
</a>

Using the exact code in my recreated site with the same theme and path to image shows a broken image link. The link shows up in the following format:

http://192.10.10.1/sites/all/themes/microsite/images/image.jpg

instead of :

http://192.10.10.1/mysite/sites/all/themes/microsite/images/image.jpg

To resolve this I set $base_url in settings.php to http://192.10.10.1/mysite but the link is still broken.

Can anyone help, please?

0

You should remove the first slash from src in your theme to

<img src="sites/all/themes/microsite/images/image.jpg" />

That first slash is indicating that it is relative to your web root rather than your Drupal root.

  • Thanks but that didn't solve the problem – sisko Dec 12 '13 at 9:02
0

Use the url() function to perform the path/URL magic for you. Note that you will have to change the block's input format to "PHP code" for this to work.

<a href="<?php print url('publications'); ?>" target="_self">
  <img src="<?php print url('sites/all/themes/microsite/images/image.jpg'); ?>" />
</a>

(All of the above could be accomplished by a call to theme_image() followed by l() but that would obscure the answer. Also, it's good practice to use path_to_theme() to get the path to the current theme.)

0

If none of these answers work, make sure you have set the RewriteBase in your .htaccess file to be in the virtual directory /mysite

# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
 RewriteBase /mysite
#
0

Try this:

<img src="<?php print drupal_get_path("microsite", "theme"); ?>/images/image.jpg" /> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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