0

I've created a custom module,having a href links like follows.

Let's say the following link appears on example.com/somepage/another-page/nid

t('<p><a class="stn" href="/my-page">Back to My Page</a></p>');

The above links works by default but it won't work if user is in Spanish version (example.com/es/somepage/another-page/nid).

If user click on the link it redirects to default lang version (example.com/my-page)

I tried $GLOBALS['base_url'] but it doesn't work in this case.

So my question is how can I give href link for multilingual? Any ideas would be much appreciated.

  • 1
    Consider using example.com instead of commercial website in your content, please. – Mołot Sep 30 '14 at 9:46
  • @Mołot Thanks for the suggestion I've changed it. Infact mydomain.com is not ours.I didn't know that domain exists :) – Krishna Mohan Sep 30 '14 at 10:00
1

You have a mistake in your code.

Wrong:

t('<p><a class="stn" href="/my-page">Back to My Page</a></p>');

Correctly

'<p>' . l(t('Back to My Page'), 'my-page', array('attributes' => array('class' => array('stn')))) . '</p>';

For more information see function l();

| improve this answer | |
  • I see we both used the same code snippet from the same api docs page :D – Mołot Sep 30 '14 at 9:48
  • Yes, thanks for that but that didn't resolve my problem. If user is in Spanish version that redirects to example.com/my-page instead of example.com/es/my-page – Krishna Mohan Sep 30 '14 at 10:07
0

Simply use l function:

l(t('Back to My Page'), 'my-page', array('attributes' => array('class' => array('whatever-class-you-need-if-any))));

It is there to take care about all that irritating details for you.

| improve this answer | |
  • Molot are you sure that it works on Spanish version too? Am I missing something? – Krishna Mohan Sep 30 '14 at 10:11
  • @KrishnaMohan it should preserve your language, and allow Drupal configuration to happen - if you configured Drupal to direct users to content in their current language, then it will (or, at least, should). – Mołot Sep 30 '14 at 10:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.