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.

2
  • 1
    Consider using example.com instead of commercial website in your content, please.
    – Mołot
    Sep 30, 2014 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 :) Sep 30, 2014 at 10:00

2 Answers 2

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();

2
  • I see we both used the same code snippet from the same api docs page :D
    – Mołot
    Sep 30, 2014 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 Sep 30, 2014 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.

2
  • Molot are you sure that it works on Spanish version too? Am I missing something? Sep 30, 2014 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, 2014 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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