I have a site setup with 'hackable' urls, meaning that removing one part of the url will reveal the parent page's content. For example:
golf - overview of golf content
golf/course-2/ - overview of course two content
golf/course-2/hole-3 overview of course 2, specific hole 3. - you get the idea
Using the token [node:menu-link:parent] I can successfully achieve what I am looking for when a menu is only 1 level and 2 levels deep. However, 3 level deep gives me (using the above example) course-2/hole-3 when what I need the alias to actually be is golf/course-2/hole-3.
Perhaps I am not using it correctly. What configuration should I use to get the entire menu path as part of my url alias? Also, it needs to be dynamic so that if a user adds another menu item, 4th level, or whatever, things will fall into place. Thanks for the help!
Comment | File | Size | Author |
---|---|---|---|
#11 | menulink.png | 76.9 KB | bones |
Comments
Comment #1
Dave ReidYou should use the token [node:menu-link:parent:url:path] which gives you the full alias of the parent menu link.
Comment #2
davidee CreditAttribution: davidee commentedThis doesn't work for me. I work with Node Hierarchy. I have it like this:
A = first level link
[node:menu-link:parent:url:path]
B = second level link
[node:menu-link:parent:url:path]
C = third level link
[node:menu-link:parent:url:path]
Am I doing something wrong?
Comment #3
davidee CreditAttribution: davidee commentedComment #4
Dave ReidThen you probably want something like [node:nodehierarchy:parent:url:path] but I cannot give out much help for things out of scope of the Token module issue queue (modules that provide other tokens).
Comment #5
davidee CreditAttribution: davidee commentedOke thank you!
Comment #6
davidee CreditAttribution: davidee commentedIt worked:) I am very happy!
Comment #7
Gastonia CreditAttribution: Gastonia commentedHey, that worked great for me, thanks a lot!
Comment #8
Gastonia CreditAttribution: Gastonia commentedThis note is off topic, but while we are on the subject, you guys may know of a solution. The next logical step for me after getting this to work is to make my breadcrumb links exactly mimic the same structure. Can anyone recommend how to do that or what to put into the template.php file? I used taxonomy menu to create my menu structure. Everything is working great except for the breadcrumbs which just say 'home'
Thanks!
Comment #9
sheena_d CreditAttribution: sheena_d commented@Gastonia: checkout the Custom Breadcrumbs module: http://drupal.org/project/custom_breadcrumbs
Comment #11
bones CreditAttribution: bones commentedThis works for me, but why isn't it in the list of Tokens? See attached screenshot.
[node:menu-link:parent:url:path] is a very useful token for creating path aliases based on the menu, and should be listed.
Comment #12
Dave ReidIf you upgrade to Pathauto 7.x-1.x-dev (not 7.x-1.0) you'll be able to use [node:menu-link:parents:join-path] which is what replaced the recommendation in this issue.
Comment #14
BrianLewisDesign CreditAttribution: BrianLewisDesign commented[node:menu-link:parent:url:path]/[node:title] -- this repeats the top level parent multiple times, for nth children in the menu. makes a mess. doesn't get the full heirarcy.
[node:menu-link:parent:parent:parent:parent:url:path]/[node:title] -- this gets the top parent only, with no repeats, down to the 4th child in the menu.
[node:menu-link:parents:join-path]/[node:title] -- perfect. this gets the whole parent menu hierarchy into the URL. that's what i was after.
Comment #15
caschbre CreditAttribution: caschbre commentedI know this is an old issue but for anyone looking for a solution... the above doesn't work perfectly. See #1496582: Manually set parent item is not included in path.
Basically the above token uses the parent items "menu title" and not the node path. So if a manual path was set on an ancestor node or if the node title varies from the menu title on any of the ancestor nodes then the url won't come out as expected.
Comment #16
jelo CreditAttribution: jelo commented[node:menu-link:parents:join-path] works very well. Is there an option to limit the depths of the parent links to prevent super long URLs?
Example: [node:menu-link:parents:join-path/3] -> for three levels deep?
Comment #17
Justincletus CreditAttribution: Justincletus commentedTry this pattern for menu and submenu item
[node:menu-link:parents:join-path]/[node:title]
Comment #18
nesstheheroApologies for bumping, but I have a question and it involves this token.
[node:menu-link:parent:url:path]/[node:title] is working in a Drupal 8.8 site as of March 10, 2020.
My question is that this token, [node:menu-link:parent:url:path], does not appear as an available token on the interface that shows all available tokens. This can be seen at /admin/help/token/.
I can find [menu-link:parent:url:path] and [node:menu-link:url:path], but nothing under the parent. It stops at [node:menu-link:parent:url].
Is this an issue with Pathauto or an issue with Token?
I realize the token is working, but it's disingenuous, confusing, and unhelpful to future users and "people not us" for this to not be documented.