0

In my anchor tag I have hard coded like this <a href="/escorts'.my_link'", I want to get the relative url path. Whenever if the path is some like this in the url http://drupal.stackexchange.com/questions/ask and I clicked on the above mentioned link then instead of http://drupal.stackexchange.com/questions/ask/my_link it gives me escorts/my_link. I know I did not convey my question properly. Hope anybody get my scenerio. Thanx

3 Answers 3

0

I didn't fully understand your question. But I imagine two cases:

  1. If you need a url that works in any page on your website, no matter where you are, you need to use this code:

    <?php  
            global $base_url;
    ?>
           <a target="_blank" href="<?php print $base_url;?>/escorts'.my_link'"
    
  2. On the other hand if you want to attach the url to the current address, use this code

    <?php  
    
            $path = current_path();
    ?>
           <a href="<?php print $path ;?>/escorts'.my_link'"
    
4
  • Thanku @Drupalist, I got the required url by using first method. But not locally it works but when I deploy it to other machine it is not clickable on the same window, I have to right click that item and open it in a new tab or window.As I am accessing using <a href="<?php print $base_url;?>'.my_link'" windows.location="<?php print $base_url;?>'.my_link'">
    – nomeer
    Commented Apr 22, 2015 at 4:52
  • I updated the answer and it opens the link another tab. just add target="_blank" to <a>
    – M a m a D
    Commented Apr 22, 2015 at 4:59
  • Sorry @Drupalist, I did a mistake above. Locally it is working and links are opening in same window and in a new tab as well, this is right. But when I deployed it to other machine they are not clickable on the same window. I always have to open it in a new link or tab. I want to make working in a same window as well.
    – nomeer
    Commented Apr 22, 2015 at 5:10
  • @nomeer it is about html <a> tag,By specifying target you can determine how to open the new page. for more information visit w3schools.com/tags/att_a_target.asp
    – M a m a D
    Commented Apr 22, 2015 at 5:28
0

Just use the l function it will take care of everything for you, in your example use:

print l('Text', 'escorts/' . my_link);
0

Solution:

It will be like this

print l('Anchor text', 'my_link');

Your Answer

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

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