0

I want to add the machine name of every node into my page.tpl.php template as a class on the body. How can I get that machine name?

I have access to the node object, but I don't see the machine name in there. Is there an api call I can use?

  • 1
    what do you mean by machine name? – Mohammed Shameem Jan 25 '13 at 18:14
  • after reading Chapabu's answer I see that I meant 'path alias' – doub1ejack Jan 25 '13 at 20:02
2

Individual nodes don't have machine names in Drupal 6 or 7, so you can't.

If you want a unique ID for each node, and Node ID won't do (for staging or migration for example), then try taking a look at the UUID module.

This module provides an API for adding universally unique identifiers (UUID) to Drupal objects, most notably entities.

Also of note...

Features in Drupal 6 version

  • Automatic UUID generation for nodes, node revisions, users and taxonomy.
  • Allow choosing which content types and vocabularies to create UUIDs for.
  • Option to batch create UUIDs for objects which don't have it already.

If, however, you want the node TYPE to be available to your template, and you have the node object, it should be under $node->type, or possibly $vars['type'].

  • 1
    ah right, thanks for that reminder. I guess I'm more interested in the url path alias than the node itself. And I see that I can just get the path with $node->path. Thanks. – doub1ejack Jan 25 '13 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.