I've added some html code in my Blocks content and enabled Full HTML filter.
I've used relative paths for my images, such as "sites/all/themes/zen/zen/image.png"
I guess this is not correct because I need to change my paths depending on I'm in the home page or "node/id" page.
I guess I cannot use PHP inside blocks, thus I cannot use $base_url... how can add images path with only html ?
thanks
Instead of the relative path, use the absolute path. So it'd be:
Note the slash at the beginning. The slash should be the only thing you need to do to convert your existing relative paths to absolute ones for use in straight HTML.
I use the CKeditor and IMCE modules to do this on my sites.
It is very user friendly and not that hard to set up.
I would recommend using the Pathologic module for this case. It is a filter that you can add to your input formats to convert relative URLs like that into proper URLs using your site's base URL. Plus it's useful if you have images in your RSS content as sites that re-publish the content (like feed aggregators, etc.) have the link to the full URL.
If you start your image paths with a slash ("/sites/all/themes/zen/zen/image.png") this will always be relative to your drupal root directory.
You could also simply select "PHP code" as the Input format, and use $base_url as you say.
I does this with cck blocks . The cck blocks is drupal module,it can put drupal fields into blocks
The previous answers provide a part of the solution, but here's a fuller scoop:
Hand-written HTML
If your site lives at example.com (i.e. it's the "root" site), then adding a front slash to your relative path will solve the issue, as others have suggested:
However, if your site lives at
example.com/my-drupal-site
, then you'll need to write it like this:It really is better if you can use PHP to determine the appropriate path. If you're calling an image from a theme, you can use the Drupal function
drupal_get_path
to get the path like this:And then you could be really Drupaly about it and use the
theme_image
function to generate the HTML for the image:Where
$img
now holds the HTML for the<img>
tag and itssrc
,alt
, andtitle
attributes. See the API documentation for drupal_get_path and theme_image for more information.Point-and-click Solution
As jeffreymb points out, your easiest bet is to use a combination of a WYSIWYG editor and a built-in file handling module called IMCE to gloss over all these details for you. If you don't have access to the "PHP code" input format, this is the best solution.
So, steps:
See this post for a little more detail on that setup process, and make sure to read the documentation that the WYSIWYG module displays on its configuration page.
Once you have IMCE installed and integrated with your WYSIWYG, when you click the "Image" button in your WYSIWYG toolbar, your normal dialog should appear but with a new little icon to open the IMCE file browser. This file browser allows you to browse your
files
folder for images or to upload new files. It also supports a modicum of image manipulation, and will automatically generate the necessary HTML once you've selected an image.