When I opened the printer friendly version of a book I found that the link to the stylesheet was broken.
It seems to be a problem with the $base_url variable missing the ending slash, as appending a slash (/) to the end fixes the problem.
This error only occurs when I'm viewing the site using the nested url of the site on my server; ie. http://myserver.com/hr_drupal6/.
The error does not occur when I view the site using my root level domain name; ie. http://myDrupalSite.com/
So while http://myDrupalSite.com/ = http://myserver.com/hr_drupal6/ links that rely on the base_url may not load when the site path is nested.
* What are the steps required to reproduce the bug?
Open the 'Printer-friendly version' of a book node
* What behavior were you expecting?
Styled output
* What happened instead?
Unstyled output
* More info: in book-export-html.tpl.php the code:
<base href="<?php print $base_url; ?>" />
<link type="text/css" rel="stylesheet" href="misc/print.css" />should create a working link to the print.css stylesheet in the misc folder. However the $base_url doesn't contain a slash at the end of the variable so the file is not found when the site path is nested.
* OS: Linux Redhat
* webserver name/version: Apache/2.2.14
* PHP version: 5.2.11
* Drupal version: 6.19
* Drupal path: http://myserver.com/hr_drupal6/
I have many sites that are edited on a development server where no custom domain name exists so I can't rely on having a root level domain name for every site.
So my fix for this was to add this function override:
function my_template_preprocess_book_export_html(&$variables) {
global $base_url;
if(substr($base_url,-1)!=='/'){
$variables['base_url'] = $base_url.'/'; //add a / to the base url
}
}
Now the links load properly in both circumstances: root domain name and nested folder url.
I wasn't sure that the tag required an ending slash but it looks like it's a best practice see: http://htmlhelp.com/faq/html/basics.html#url-slash
...
If the current document's URL ends with a slash, then the final segment (the "file") of the URL is null. If you remove the final slash, then the final segment of the URL is no longer null; it is whatever follows the final remaining slash in the URL. Removing the slash changes the URL; the modified URL refers to a different document and relative URLs will resolve differently.For example, the final segment of the URL http://www.htmlhelp.com/faq/html/ is empty; there is nothing after the final slash. In this document, the relative URL all.html resolves to http://www.htmlhelp.com/faq/html/all.html (an existing document). If the final slash is omitted, then the final segment of the modified URL http://www.htmlhelp.com/faq/html is "html". In this (nonexistent) document, the relative URL all.html would resolve to http://www.htmlhelp.com/faq/all.html (another nonexistent document).
...
The exception is when you refer to a URL with just a hostname (e.g., http://www.htmlhelp.com). In this case, the browser will assume that you want the main index ("/") from the server, and you do not have to include the final slash. However, many regard it as good style to include it anyway.
I don't know if this should be addressed at a higher level in the drupal core but I think it could be confined to book-export-html.tpl.php.
Some coding conventions may be in place elsewhere already that expect the slash to be stripped from the $base_url var, but I would guess that anywhere that builds a tag could benefit from the ending slash; book-export-html.tpl.php was the only place I found it in drupal 6.19 core.
Thanks
Comments