Drupal - How can I add relative path to a pdf file link in drupal menu
The thing with the menu system is that what you are typing is not a relative path, but an internal Drupal URL.
Since what you are after is not a Drupal path, but instead a static file server outside of Drupal by your webserver your options are limited.
- You can write the full url like you tried yourself
- You can create a module/theme where you can make this possible, either by adding the extra link or creating a drupal path that redirects to the static file.
Of these, I personally think that a an absolute path is the lessor of evils, unless you need to do this a lot of times.
Just use the Menu Token module. Copy your absolute PDF url to your path textfield and replace the servername with [site:url]. Also make sure the uses tokens checkbox is activated and save your menu item... In combination with the Menu Attributes module you could even link your PDF's to a blank browser tab/window if you like so.
Drupal uses "clean URLs" so when you're on the node/123
page and you are visualizing a link such as:
<a href="sites/all/myfiles/file.pdf">PDF file</a>
Your browser will interpret it as "node/123/sites/all/myfiles/file.pdf" which won't work. You have to put a "/" at the beginning of the URL:
<a href="/sites/all/myfiles/file.pdf">PDF file</a>
Of course, if your site is in a subdirectory, you need to append it; the safest way is to use l()
:
<?php echo l('PDF file', 'sites/all/myfiles/file.pdf'); ?>
Edit Dic, 18: use l()
as per kiamlaluno advice.