4

SCENARIO:

  1. I created taxonomy terms with 3 depth levels. Example:

    Term 1 ( Root )
       Term 2 ( Child of Root )
          Term 3 ( Child of Term 2 )
    
  2. In the URL Alias for my vocabulary I set:

    [term:parent:parent]/[term:parent]/[term:name]
    
    That successfully creates a path that looks like this:
    
    "http://mydomain.com/term-1" for the root term
    "http://mydomain.com/term-1/term-2" for the root's child term
    "http://mydomain.com/term-1/term-2/term-3" for the child's child term
    
  3. In my Content Type, I created a Term Reference field that forces the user to select the deepest term ( 3rd term down ) with the help of Simple hierarchical select module.


ISSUE:

When creating nodes, I would like to set the node's URL Alias to term-1/term-2/term-3/node-tile. I am having trouble finding the Replacement Pattern for doing just that.

Does path auto allow me to do that out of the box? If so, what pattern should I use?

8

There are some advanced uses of tokens (not sure off the top of my head if that's just in the context of pathauto or not). You can get what you're looking for with join:

[node:field-name:parents:join:/]/[node:field-name:name]/[node:title]

You could also replace your term pattern with:

[term:parents:join:/]/[term:name]

Using that method your vocabulary can grow gracefully to 4 (or more) levels without having to change the pathauto pattern.

You'll need to go to admin/config/search/path/settings and set the Slash (/) option to "Do not Replace" under "Punctuation" for that method to work.

  • Ok, I am still having trouble. Please take a look at this screen shot here bit.ly/14vs8xu . It shows the available tokens for my taxonomy field under "Content Paths". Notice that tokens like [node:field-main-menu:parents... and [node:field-main-menu:name] is not available and sure enough drupal complains about it when I try to save. Non of those tokens seen on the screen shot actually work but [node:field-main-menu] which returns the deepest term item ( Term 3 ). Would you have a clue of what might bee the issue here? – Francisco Luz Jun 11 '13 at 22:53
  • Do you have the Entity API module installed? As @Елин Й. mentioned that's required, I forgot to add that – Clive Jun 11 '13 at 23:15
  • Yes I do have Entity API. I've just figured out what was wrong. My field was set to unlimited values. Now both solutions, yours and @Елин Й work beautifully. Thank you very much both of you. – Francisco Luz Jun 11 '13 at 23:25
4

Yes there is a token for that. Assuming the machine name of the Term Reference field in your content type is field_myterm, the pattern for the path should be:

[node:field-myterm:parent:parent]/[node:field-myterm:parent]/[node:field-myterm]/[node:title]

Notice the underscore in the field name is replaced with a dash in the token.

Edit: I just realized that these tokens come with Entity Tokens module which is included in Entity API module.

  • Thank you Елин Й. Both solutions, yours and Clive's, work as gold. – Francisco Luz Jun 11 '13 at 23: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.