I have a teaser type, and all the other variables are working for anonymous users, but not the $path. I've been able to get around it by using $nid in this case, but has anyone else seen this?

Comments

colm_iqc’s picture

Fix for this would be really appreciated.

colm_iqc’s picture

Priority: Normal » Critical

It seems to be something to do with the administrating the urls:

Turning on the following option for all users makes it work.
path module - administer url aliases

markhope’s picture

Yes a fix for this would be extremely welcome. Allowing anonymous users to administer paths does fix it - but I'm not mad enough to apply that on a live site!

I hadn't noticed this problem as I'm nearly always logged in. damn.

jeffabailey’s picture

I have the same problem, a fix would definitely be appreciated.

visualnotion’s picture

Yes, a fix would be great. Does anyone know if you can get around this by using CCK template files and bypassing Content Template?

czheng’s picture

ditto above. would love to see a fix for this.

ncameron’s picture

Hey there,

This is not a fix but a nifty work around until it can be patched up. Slip this snippet of code at the top of your .tpl.php file and if the $path variable is unset then it will replace it look up the url alias and set $path as that.

<?php //If $path is empty (for anon) it replaces it with the correct path from the below function
if (empty($path)){
	$nodeIDpath= 'node/'.$node->nid;
	$path = drupal_get_path_alias($nodeIDpath); 
	}
?>

Hope this helps. Any thoughts, feedback appreciated.

Thanks,

Neil

-----------------
Connecting Language Learners
www.huitalk.com

technivant’s picture

Thanks! It dind't work for me in my .tpl.php so I stuck this in my content type template (a la contemplate) and changed $node->nid to $nid and it works perfectly.

jaysmall’s picture

I couldn't get either of the two snippet methods suggested above (e.g., in template file or Contemplate custom teasers) to work in my teaser blocks in a 5.0 installation. But the following, in my Contemplate custom teasers, does work. Does anyone see a problem with this implementation?

<a href="<?php print drupal_get_path_alias('node/'.$node->nid); ?>">...</a>

Thanks.

maastrix’s picture

I had the same problem. Put your line of code in my node-type.tpl.php and now it works like a charm. Thanks.. Seems okay.

Brian.Harris’s picture

Also if you use pathauto you can use

<a href="<?php print url("node/$nid");?>">my link</a>
ludek.safar’s picture

Yep, tried with success, problem seems fixed. Thanks a lot!

marcoBauli’s picture

tip at #7 above works great in views templates generated by Views Theme Wizard :) Thanks!

wilco’s picture

Title: print path in teaser for anonymous users doesn't work » Path / Clean URLs not showing up - anonymous users don't get a path
Project: Content Templates (Contemplate) » Path
Version: master »

I came across this issue recently when playing with Clean URLs and URL Aliasing with Views in Drupal 5.1. An anonymous user browsing the site would get all explicit URL Aliases but all the paths created dynamically from the View Module were not showing up.

I did some snooping around and found a solution suggesting modifying the node.tpl.php to add a few lines of code. In doing some thinking I came up with a solution that worked more thoroughly. I found, as in my case, having to modify and keep updated a large set of node.tpl files to cumbersome. Here is my template.php solution:

// This code snippet works well with Drupal 5.x
function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
  	case 'node':
		$node = $vars['node'];
		if (empty($node->path)){
			$nodeIDpath= 'node/'.$node->nid;
			$node->path = drupal_get_path_alias($nodeIDpath);
			$vars['node'] = $node;
		}
		break;
	}
	return $vars;
}
sgriffin’s picture

Awesome thread, just got bit by this with cck to sum up.
use url("node/$nid") not $node->path

Not sure even why $node->path is listed.

Tom-182’s picture

I've tried the solution on #14, adding the codes to template.php didn't work on my Drupal 5.1 site.

Tom-182’s picture

I finally use the solution in http://drupal.org/node/146477 and it works like a charm.
Just use print drupal_get_path_alias("node/$node->nid"); to load the path in Contemplate.

texas-bronius’s picture

url("node/$nid"), drupal_get_path_alias('node/'.$node->nid) and other derivatives suggested herein work well, but not with the Contact Module (and I expect some other modules..?) On my contact pages path-aliased like "meetings/contact", "banquets/contact", the suggested workarounds return node/. Node types, however, work like a charm.

I think the fix should be to simply append path to $node regardless of whether a user has path admin privs or not. A bigger fix might be to rely not on Path module's modification of $node but something lower level and hanging off $variables, to be used independently of Path.

ceejayoz’s picture

I'm baffled that this is apparently a long-standing issue. Having the site be entirely unusable by anonymous users would seem to be a fairly significant problem...

I just commented out the check in path_nodeapi() for user permissions (first line of the function) - it's a better option than enabling anonymous users to administer paths, unless I'm missing something major.

nosro’s picture

Agreed with #18 - I ran into this problem when using the Services module, and I can't use the suggested workarounds to get the path to be included in my service. My only options seem to be to modify the Services or Path modules.

summit’s picture

Hi,
Subscribing. Anonymous users should not be handled differently regarding clean-url's in my perspective.
greetings,
Martijn

Anonymous’s picture

OK... after having looked through this whole issue... I found that the problem actually lay within the path.module file of the path module. I have version 5.5 of drupal and the problems were the same for me. No need for these contemplate workarounds or .tpl.php
fixes.... edit the path.module file found in drupal's "../module/path" folder like so:

goto line 214 or do a search for " ('administer url aliases') " in your text editor.

you should come upon this...

function path_nodeapi(&$node, $op, $arg) {
  if (user_access('create url aliases') || user_access('administer url aliases')) {
    switch ($op) {

CHANGE IT TO THIS:

function path_nodeapi(&$node, $op, $arg) {
  if (user_access('create url aliases') || user_access('administer url aliases') || $op) {
    switch ($op) {

Works in both IE and Firefox... hope this is the real fix!

HAPPY NEW YEAR

Anonymous’s picture

PS... if you happen to see <b> || $op </b> this is because the server has not yet refreshed its cache.
normally it should just say ...aliases') || $op) {

summit’s picture

Hi,

I think this should be put in a patch so with an update the changes are not gone, right?

greetings,
Martijn

tj2653’s picture

I just stumbled across this issue when I realized two of my links with $node->path wasn't working for anon/regular users. The patch in #22 seems to fix it for me. Thanks rudeboyal!

robloach’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.