I would like to get the raw URLs of the nodes collected in my Views query. I can't seem to find a Field that is devoted to this purpose.

Yes, there is a node link field, but I need the raw URL itself to pass it into a multimedia piece.

Yes, I can grab the nid and scrap together a working URL but I would much rather use the URL alias.

Is there:
1) some sort of a Drupal function that will output a URL alias if I pass it the NID?
2) a field I'm just not seeing withing the Views Fields that will yield the URL alias?

Thanks so much for your time!

Edited by WorldFallz - moved to appropriate forum.

Comments

WorldFallz’s picture

you could probably get this working by using drupal_get_path_alias in a http://drupal.org/project/views_customfield.

ecksley’s picture

Thank you!

I am using a tpl.php to theme the View so I just inserted the function call in the markup... didn't even need the customField module, although it's great to know it exists.

For anyone else using a tpl.php the code I used to grab to correct alias looked like the following:

$targetPath = "node/";
$targetPath .= $row->nid;
$targetPath = 'http://'.$_SERVER['HTTP_HOST'].base_path().drupal_get_path_alias($targetPath, $path_language = '');

Sorry I posted in the wrong forum. I just thought this was theming related.

estone’s picture

Thanks Ecksley, i needed just that to do something similar...

jared12’s picture

Good info! Thanks.

machinez’s picture

In case someone does want to output url_alias in views using customfield php

$targetPath = "node/";
$targetPath .= $data->nid;
$targetPath = 'http://'.$_SERVER['HTTP_HOST'].base_path().drupal_get_path_alias($targetPath, $path_language = '');
print $targetPath;

Great from Google Merchant and Ubercart product nodes.

lolandese’s picture

Thanks. I used this piece of code to generate a FB share button that points to the intended node for each displayed node in the view. See here.

visuallemon’s picture

Hi, im using this code on my custom field:php code in my view. but it doesn't get language of the node. what it gets its just node path alias. any advice on this one would be highly appreciated

solipsist’s picture

You can simplify your code considerably by using Drupal's API more:

print url('node/'. $data->nid, array('absolute' => TRUE));

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

carl.brown’s picture

I came accross this answer and it does exactly what I wanted in a very succinct way, but for some reason it doesn't work - unless I use 'print' twice! - Any idea why this might be? If I write this in my page.tpl.php:

<?php
print url('node/'. $data->nid, array('absolute' => TRUE));
?>

I get no output, but if i write this:

<?php
print print url('node/'. $data->nid, array('absolute' => TRUE));
?>

Then I get the raw node ID?

chike’s picture

Thank you so much, this worked for me.

bwoods’s picture

I was looking for the same thing. Thanks!

Murz’s picture

In views 3.x you can use "Path" field with option "Use absolute path" in Rewrite field group.

rpai’s picture

This is what I needed.

pal4life’s picture

Weird for me even in Views 3.x using with Services, the Path does not fill up.

zeroyon’s picture

prints the complete url with correct alias

<?php
$targetPath = drupal_lookup_path('alias',"node/".$node->nid);
$targetPath .= $data->nid;
$targetPath = 'http://'.$_SERVER['HTTP_HOST'].base_path().drupal_get_path_alias($targetPath, $path_language = '');
print $targetPath;
?>