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
Add a comment
|
3 Answers
I didn't fully understand your question. But I imagine two cases:
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'"
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'"
-
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'">
– nomeerCommented Apr 22, 2015 at 4:52 -
I updated the answer and it opens the link another tab. just add
target="_blank"
to<a>
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.– nomeerCommented Apr 22, 2015 at 5:10
-
@nomeer it is about html
<a>
tag,By specifyingtarget
you can determine how to open the new page. for more information visit w3schools.com/tags/att_a_target.asp Commented Apr 22, 2015 at 5:28
Just use the l function it will take care of everything for you, in your example use:
print l('Text', 'escorts/' . my_link);