Hi,

The PHP code in the template only works when I am logged in as the administrator. It's not available to the users.
I am trying to embed a flash file from a directory and I have the following code to do it:

// Remove the - from the title
$gtitle = preg_replace('/-/', "", $node->path);

// Create the path to the flash file
// Path = games/title/title.swf
$gpath = "games/".$gtitle."/".$gtitle.".swf";
// Creat path to the gif file to use for icon.
$gicon = "games/".$gtitle."/".$gtitle.".gif";

$node->picture = $gicon;
print $node->picture;
print "\n";

It's rather basic but the variables like $node->path are only defined when I am logged in as admin. I tried printing all the variables out and only $node->vid seems to be always defined. The rest ONLY get defined when user1 is logged in. How can I work around this issue?

You can see the issue and the DEBUG messages I printed here: http://jokenuts.com/drupal/
Just search for the word DEBUG on the page.

Please advise.

Thanks,
-Arman

Comments

alxbkh’s picture

path module works only with admin permissions, use $node->nid instead... or $node->title maybe

jamiers’s picture

path module works only with admin permissions, use $node->nid instead... or $node->title maybe

Is this by design? I posted this question in the pathauto and they said it wasn't a problem with pathauto. It seems silly to use the $node->path if it isn't available to anonymous users. This is the information that I posted at pathauto:

Referencing the information here:
http://drupal.org/node/155507

I am a new person to drupal and am trying really hard to understand all the intricate workings of the system. I am currently using pathauto to name my school's podcasts by name and episode (for example Radio001 or TV001). The pathauto works great until I try to create a link in a teaser that states "Click here to listen to this episode." I use the $node->path item in the Contemplate module template, but it will not provide the path if the person is anonymous (not logged in). People will not be logging into the site to listen/watch.

Is the above link correct in its statements... and is there any way around this without linking to node/number.

Thanks...Jamie

My stories currently use relative links (../subscribe or ../go/link). When I use the "node" method, those links get botched up. There isn't any way around the $path->node being only available to users logged in?

Thanks for your help.

Jamie

aohanian’s picture

Hi Jamie,

I used $path->title for my purpose. It isn't the best solution, but it works for the time being.

I used it to load the games from a predefined location. It doesn't work for all the games because "title" and "path" variables are not always the same.
If you like to check it out, here is my site http://www.jokenuts.com/drupal/ ( still under construction).

Scroll down for the games. I used the $node->title to derive the icon locations from the contemplates.

Good luck.

-Arman.

blb’s picture

i agree that this is not the way it should work - seems like a bug.

the workaround that i used is this:

drupal_get_path_alias('node/'.$node->nid)

that worked for me.

jjeff’s picture

Status: Active » Closed (works as designed)

This is not a bug with anything per se. However, the permission for this code is being generated on line 214 here:
http://cvs.drupal.org/viewvc.py/drupal/drupal/modules/path/path.module?a...

For some reason path module only adds this information for users with administration access.

It depends on your use case, but either url('node/'. $node->nid) or drupal_get_path_alias('node/'. $node->nid) are what you want...

liquidcms’s picture

yup, just stumbled upon this same issue.. very odd.. and i would say it is certainly a bug..unless someone can explain a good reason why path alias should be usable in tpls ???

markosef’s picture

Yes i agree with all. Path would be used for nicer URLS that would be SEO friendly and i don't think SE like to login to drupal and than do their search :-)
Many ppl like me would try to use something like

print "<a href=\"".$node->path."\">".$node->links['node_read_more']['title']."</a>";

but that works only when logged in, so correct way or WA is

print "<a href=\"".drupal_get_path_alias('node/'.$node->nid)."\">".$node->links['node_read_more']['title']."</a>";

gives same result as the one when logged (thanx blb)

summit’s picture

Subscribing, greetings, Martijn

maxiorel’s picture

subscribing

UnicornSong’s picture

Subscribing..

I have this issue. the template is not used at all when not logged in.

I added a template to merely try to overcome weirdness in the content type's field order.

<?php print $node->body ?><div class="field field-type-image field-field-product-image">
  <h3 class="field-label">product_image</h3>
  <div class="field-items">
      <div class="field-item"><?php print $node->field_product_image[0]['view'] ?></div>
  </div>
</div>

<div class="field field-type-text field-field-quote">
  <h3 class="field-label">quote</h3>
  <div class="field-items">
      <div class="field-item"><?php print $node->field_quote[0]['view'] ?></div>
  </div>
</div>

<?php print $node->body ?>

<div class="field field-type-number-decimal field-field-price">
  <h3 class="field-label">price</h3>
  <div class="field-items">
      <div class="field-item"><?php print $node->field_price[0]['view'] ?></div>
  </div>
</div>

Which works fine for administrator, we now see the price div as the last div.
But when an anonymous user views the page the html structure is so:

<div class="node-inner">
 <h2 class="title">
  <a href="/content/blah-blah">
    Title Text is here</a>
 </h2>
<div class="submitted">
      Submitted by admin on Fri, 06/13/2008 - 14:48.
</div>
<div class="content">
  <div class="field field-type-image field-field-product-image">
    <div class="field-items">
      <div class="field-item">
            <img src="http://thesite/files/brg/theimage.jpg" alt="" title="" height="128" width="120">
      </div>
    </div>
  </div>
<div class="field field-type-number-decimal field-field-price">
  <div class="field-items">
    <div class="field-item">
      299.5
    </div>
  </div>
</div>
   <p>
       The body text is displayed here
   </p>
 </div>
</div>
</div>
<!-- /node-inner, /node -->