Know Base Path function for Drupal with Multilanguage (i18n version 2.1)

My problem was that I want imagefield that user can click in Teaser view, then, bring user into the node. (Default without contemplate, the click will do nothing. By clicking at the title is the only option.)

By wring the code in contemplate, there are 3 parts that I need to do.

1. A function to get Basepath (Ex.www.bxtra.net)
2. A function to get i18n path (Ex.en, fr, etc.)
3. A function to get node that the link will go to.
It will end up like this -> http://www.bxtra.net/en/node/4

I'm not a drupal expert at all and I just did online search for what I want and tried that. So, I've tried a few options below :

1. <a href="<?php print base_path().i18n_get_lang().'/node/' . $node-?>nid ?>">  

Result : http://www.bxtra.net/en/node/4

2. <a href="<?php print $base_path.'/node/' . $node-?>nid ?>">   

Result : http://www.bxtra.net/node/4

3. <a href="<?php print url("node/$node-?>nid"); ?>">   

Result : http://www.bxtra.net/en/node/4

 

For option 2, it works fine since the i18n will pick current language for you. So, no need to put /en/ at all. Whatever language you're using, it will stick to that language.

I also had tried using the function base_path() in the option 2 before I found $base_path and the result was not what I'd expected. I got http://node/4 which was not correct. I had no idea why the same function, just without i18n_get_lang() showed a different result.

Actually, I'd used option 1 for quite a while and looked into something different than option 1 because I usually got error page like

          ->  http://www.bxtra.net/en// (Double trailing slash) 

I don't know why the program generated that page and I thought that it could be because of the code I'd used. So, right now, I switched to option 3 and see if I still got the same problem or not.

Comments

Hi friend. I don't speak in enlgish very well. But I understand you question. All the links in Drupal should called via "l" function, so, if you have activated the i18n the function "l" will convert the link to correct Drupal link. I hope you understand. Best, Dario dario.php@gmail.com

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.