2

I statically added a link to /cart on the page.tpl.php template file. Since it's a multi language website, the link doesn't always work.

How do I print a link that consider the currently used language?

0

4 Answers 4

9

If you want to display the cart link in a template you better do it with l() or url().

<ul>
<li><?php print l(t('Cart', 'cart')) ?></li>
<li><a href="<?php print url('cart') ?>">Cart</a></li>
</ul>
0
4

This should work in your page.tpl.php

global $language;
global $base_url;
//get the current language
$current_lang = $language->language;
//get the default language
$default_language = language_default();

switch($current_lang) {
  case($default_language):
    $url = $base_url."/cart";
    break;
  default:
    $url = $base_url."/". $current_lang ."/cart";
}

I added the language_default() part as per Clive suggestion. You'll find more information on global $language.

0
3

If you just need to print "en" or "nl" somewhere, depending on the current language:

<?php
  global $language ;
  $curlang = $language->language;
?>

This is the prefix of the current language: <?php print $curlang; ?>
0

cptstarling is correct. I was getting error's back from SEO reports asking for Language declarations, and simply created a custom HTML.tpl.php theme template that included:

<!DOCTYPE html lang="<?php echo $language->language; ?>">

I did not declare a variable, as this was the only location that I needed the PHP language to be displayed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy