chirale

IT and beyond

In contemplate and views, $node->path return current page path. But this variable is only available to users with “administer alias” permission, so as administrator you can view links, but as normal user you cannot use them.

Here a $node->path alternative:

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

Since $node->title is raw input, strip_tags strips all HTML tags.
A node/$node->nid links to article. Drupal link function returns the (in case) aliased path.

4 thoughts on “Contemplate and views: create a link without $node->path

  1. Tim says:

    Thanks. I was stumped for a bit and this exactly what I needed.

  2. Agen says:

    Wouldnt it be easier to say:
    ….”?q=”.$node->nid)
    Your proposed solution works with clean urls, and this should with both i suppose

    Thanks for the tip

  3. Amre Ellafi says:

    very useful hint ! ,as Agen suggested “?q=” is much cleaner

  4. chirale says:

    Even if I ever activate Clean URLs, l() Documentation expose reports only the example without “?q=”, so I assume that version is correct.

Leave a Reply to Amre Ellafi Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: