I have created menu link for a pdf file. I can use a full path like "http://website/sites/all/myfiles/file.pdf", but if I try to put a relative link such as "sites/all/myfiles/file.pdf" it does not work. If anyone has idea please tell me.
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
<?php echo l('PDF file', 'sites/all/myfiles/file.pdf'); ?>
Edit Dic, 18: use
l() as per kiamlaluno advice.
Create a new content type (e.g. "file download")
Give it a field URL (a link, or a regular text field)
- Override the template file used in your theme (e.g. node--file-download.tpl.php)
In this file, put the PHP code to load the field with the URL of file, and then put the following code:
Create a pattern in the Pathauto module for this kind of content type (e.g. "file/download/name" or "download/file_id")
- Then, you can put it in the menu without problems
I bet there's an easier way, but this should also do the work. It should be double considered in a matter of security.
Just use the Pathologic module, and your relative links will work just fine.
You can also use Menu HTML module together with Special Menu Items module . This will allow you to place anchor pointing to you file as Menu link title, and nolink tag as menu path.
Just take a look at the screenshot: