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 HTML markup is the following.

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

Using the exact HTML markup in my recreated site with the same theme and path to image shows a broken image link. The link shows up as 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?

4 Answers 4

1

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

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.

1
  • Thanks but that didn't solve the problem
    – sisko
    Commented Dec 12, 2013 at 9:02
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 and acknowledge you have read our privacy policy.

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