Heine

  • home
  • drupal
  • drupal core commits
  • about
Home › Drupal

Drupal 6: $base_path doesn't always point to the frontpage

Heine — Sun, 17/05/2009 - 19:13

Dear themers,

<a href="<?php print $base_path ?>" title="<?php print t('Home'); ?>" ...

.... in page.tpl.php breaks Home functionality on many multilingual sites.

Consider a multilingual site with English (prefix 'en') as the default language and Dutch (prefix 'nl') as a second language. While browsing the site in Dutch (eg http://example.com/nl/node/5), the homelink created with $base_path leads to http://example.com/, which is the default English content. Quite an unpleasant surprise for your visitors.

The correct URL to the homepage is $front_page. As this variable holds a URL, you still need to convert it to HTML by calling check_url on it:

<a href ="<?php print check_url($front_page) ?>" ...

If you maintain a theme on Drupal.org that doesn't use $front_page, please consider this a bugreport. Thanks.

Average: 4.2 (11 votes)
  • Drupal
  • Multilingual
  • Planet Drupal
  • Theming

Theme resources...

Nicholas Thompson (not verified) — Mon, 18/05/2009 - 08:51

Good point - the URL to the frontpage should be $front_page (/me goes off to check Abessive!)...

But $base_path has its place; access to theme resources. Shouldn't you link to images using:

echo theme('image', base_path() . path_to_theme() . '/images/blah.png');

Also - should you use $base_path or base_path()?

  • reply

$base_path, $directory

Heine — Mon, 18/05/2009 - 11:25

In page.tpl.php $base_path is available, so by all means, use $base_path there. In other .tpl.php files you need to call base_path() yourself, or make your own $base_path variable in template.php.

template_preprocess() always fills $directory —why not $base_path is beyond me—, so there's no need to call path_to_theme().

Now, theme_image accepts as path: "Either the path of the image file (relative to base_path()) or a full URL." The code above should read:

print theme('image', $directory .'/images/blah.png');

  • reply

Post new comment

I reserve the right to edit any comment submitted to the site. If your comment contains flaming, advertisements, or simply too many spelling errors (leet speak), it may never appear.
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <as>, <as3>, <csharp>, <diff>, <drupal5>, <drupal6>, <html>, <js>, <mysql>, <php>, <phpbrief>, <python>, <sql>, <plain>, <xml>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

Recent posts

  • The Joomlafication of the Dutch-speaking community
  • Upgraded from 6.14 to 6.15, but Drupal still thinks it's 6.14?
  • Google Friendconnect Drupal module not recommended (yet)
  • The OpenID 2.0 Compliance Crusade - Part I
  • Using <embed> for XSS
more

Security reviews

  • Afraid custom code makes your site vulnerable?
  • You don't really trust that module you just downloaded from Drupal.org?

Sleep better after a security review.

Tags

Captcha CSRF DOH! Drupal embed Input Format modx OpenID Performance Planet Drupal Security Varnish
more tags
  • home
  • drupal
  • drupal core commits
  • about

Copyright © 2010 by Heine Deelstra. All rights reserved.