27

How do I get pathauto under Drupal 7 to generate a URL alias by the full menu path?

apaderno
  • 28,547
  • 16
  • 75
  • 90
dantz
  • 1,842
  • 4
  • 21
  • 25
  • Also see http://drupal.org/node/860082 in the Token module issue queue; we need to figure out what exactly is the purpose of those tokens, what they need to be named, etc. – Dave Reid Jan 13 '11 at 21:25

10 Answers10

45

Just an update in case anyone comes across this with a more recent version of Pathauto/Token. This worked for me:

[node:menu-link:parents:join-path]/[node:menu-link]

Ian Link
  • 684
  • 1
  • 8
  • 11
  • Works perfectly for me. Thank you. Just in case anyone is wondering, I'm using Drupal 7.14, Pathauto 7.x-1.1, and Token 7.x-1.1 (The latest versions as of 2012-07-16). Cheers. – Mario Awad Jul 16 '12 at 10:01
  • 4
    In case the node is not added to a menu. I prefer using the node title as the final segment/token. This will prevent the node from having no url alias if forgotten: [node:menu-link:parents:join-path]/[node:title] – spatical Feb 22 '14 at 22:59
  • Also note that the join-path of the parents refers to the title of the parent and not the url. So this could cause conflicts if you change the title of the parent and then create the alias of the child. – AlxVallejo Sep 25 '14 at 14:07
10

I ended up using:

[node:menu-link:parent:url:path]/[node:menu-link]

Heavy caution though: If the node does not have a menu link, you'll end up without an automatically aliased page. On the bright side, this might make you aware of orphan pages. (Consider it a feature!)

Note that using the pattern:

[node:menu-link:url:path]/[node:menu-link]

will only give the node's menu link, not that of the parent (which would be needed to reference the parent's path).

Or the pattern: [node:parent:url:path]/[node:menu-link]

throws an error in my instance of Drupal 7 about invalid tokens (even though I have the token module installed).

  • 1
    I think `[node:parent:url:path]` should definitely throw an error as your node doesn't have a parent (unless you have a custom node field called parent). Your node, optionally, does have a menu link parent when it's put in a menu, that's why your first pattern works, and your last doesn't. Cheers. – Mario Awad Nov 04 '14 at 13:14
  • @MarioAwad Thanks for the comment for future viewers. I don't use Drupal anymore, but your theory sounds logical. –  Nov 04 '14 at 14:38
  • Yep was future proofing the answer. What are you using instead of Drupal? Will be good to learn. Cheers. – Mario Awad Nov 04 '14 at 14:44
  • 1
    I've since switched to a Python/C stack. Cheers –  Nov 04 '14 at 15:20
9
[node:menu-link:parent:url:path]/[node:title]

If the node is not in the menu, then it does not create an alias. Otherwise this seems to work for n-tier menus.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
Kenan
  • 3,560
  • 1
  • 18
  • 7
5

I think it has to be this pattern now:

[node:menu-link:url:path]/[node:menu-link]

"path" instead of "alias"

  • 2
    I used: `[node:menu-link:parent]/[node:title]` Which works as expected. – Albert Skibinski Oct 04 '11 at 13:08
  • 1
    John Robinson Jr's solution does not work well in D7 -- it creates: "/node/1/about" and "/node/2/contact" etc... @askibinski -- this option almost works, but does not work if the menu item is at a greater depth than 2: "/about/members/member" becomes "/members/member" The best option is below, posted by tristan and Kenan : [node:menu-link:parent:url:path]/[node:title] -- see http://drupal.org/node/1354244 – tmsimont May 08 '12 at 16:27
2

You'll need to install the contrib Token module as well -- although a lot of the features of Token are part of core in D7, some of the edge case tokens (like the full menu path of a given node) aren't provided by core automatically.

With that installed, I believe that [node:menu-link:parent] or [node:menu-link:parent:url] should work.

Eaton
  • 7,405
  • 2
  • 26
  • 24
  • Unfortunately none of these tokens do what I want. First one gives me only the parent but if a Menu-Item is on the third level the first one will be missing. And the last one gives the absolute path to the parent node. – dantz Jan 14 '11 at 09:49
  • 1
    Using [node:menu-link:parent] or [node:menu-link:parent:url] is not a good solution. We ran into cascading issues where node aliases were being badly named because the parent menu was not named properly. And these tokens do not calculate the full menu tree leading to the node being saved. You have to really fix the parent item of a menu item in order to see any change. – asiby Mar 28 '12 at 23:20
2

The pattern that works for me is the following:

[node:menu-link:parent:url:alias]/[node:menu-link]

I also intalled the Token module like Eaten suggested. Don't know if [node:menu-link:parent:url:alias] is part of core or lives in contrib.

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
toon.ketels
  • 201
  • 2
  • 4
1

If you're attempting to make aliases for pages that are 3rd level or deeper, for example:

Home page
 > Level 1 page
   > Level 2 page
     > Level 3 page

and you want the alias for Level 3 page to look like http://domain.com/level-1/level-2/level-3, I got it to work for me by setting my pattern to:

[node:menu-link:parent:parent:parent:title]/[node:menu-link:parent:parent:title]/[node:menu-link:parent:title]/[node:title]

Notice that I added :parent to the token, and for the first one I added it twice.

Pubby
  • 51,882
  • 13
  • 139
  • 180
csuggs4
  • 29
  • 5
  • This only works if you have exactly a depth of 3. See tristan and Kenan's solutions below.. much better and more flexible. – tmsimont May 08 '12 at 16:29
0

Enjoy!

[node:menu-link:parents:join-path]/[node:title].html

Stephan
  • 41,764
  • 65
  • 238
  • 329
iwish
  • 3
  • 2
0

This is the solution I use:

[node:menu-link:parents:join:/]/[node:menu-link]

It will separate parent menu items with a dash. That is what I need.

Marcos Buarque
  • 3,318
  • 8
  • 44
  • 46
0

For anyone who stumbles upon this answer, and wonders how to add this:

Configuration > Search and Metadata > URL aliases, then create under "Patterns" tab.