Is it possible to create a link to a node using noderef that will link to the path that has been created using path (and/or pathauto). I tried, but I was only able to find the node ID so I could only make a link like www.example.com/node/1 instead of www.example.com/path-created-by-pathauto

rvk

Comments

nevets’s picture

Given the node id and the l() function (that's a lower case L) you can do something like

print l(t('link text', "node/$nid");

and the resulting link will use the path alias if there is one.

rvk’s picture

thanks I'll give that a try!

rvk’s picture

added a missing ")"

print l(t('link text'), "node/$nid");

and it works except that it ignores $nid

but when I use e.g. "node/5" it works fine! So almost there...

I tried this out in a page... is that my problem maybe?

nevets’s picture

You will need to set $nid, your original post suggested you already add access to it.

rvk’s picture

Thanks, sorry but that was more me struggling with PHP. I know how to get $nid using noderef and contemplate, but I assumed it also to be a global variable when viewing any test page. That apparently is not the case...

Thanks for your help!

mrbangkok25’s picture

Hi,

I have the exact same problem you had last year.

l($content->title, "node/$nid")

only creates a link to ../node/

It ignores the $nid.

It seems when i read the thread that you have solved the problem, if so could you please share you solution?

Thankx