I have a field type called "Venue". If the Venue is in the US, I want the path to be:


But if it's in any other country, the path must be:


In other words, non-US venues must get their country code appended to the front.

Is this even possible with the current PathAuto module? Or how can one do this?

  • 1
    I imagine you're going to have to create a simple module with a hook - i've done a similar thing. You can still utilise pathauto for generating the aliases, using the pathauto.alias_cleaner service. – user34185 May 8 '17 at 10:09

The easiest approach is to define a custom token using hook_token_info() and hook_tokens(). Based on the venue, you either return the country code or nothing. If the token has no value, pathauto will automatically clean it up and drop that part.

Pathauto tokens for taxonomy terms except root for example has some hints on how to implement custom tokens.


Follow these steps (first enable token module):

  1. go to Configuration > Search and metadata > URL aliases > Patterns
  2. select "Pattern type" as "content"
  3. Add "Path pattern" (Click on "Browse available tokens" and select fields from token list.)
  4. You can choose " Content type"
  5. Add label. 6 Save.

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.