1

I created a website with some content nodes in D8. Right now, all the nodes are on the same level, however, I would like to achieve something like this:

- Products
- - Product A
- - Product B
- - Product C
- About Us
- - Offices
- - Contact

Naturally, I would like the nodes' URLs to respect the hierarchy, so that there would be URLs like mydomain.com/products and mydomain.com/products/product-a and so forth.

I know about Node Hierarchy being available for 7, but it seems there's no such solution for D8 - however, since this is such a basic requirement, I suppose there's a way how to do this I don't know about. So, how to? Is the book module maybe the right solution for this?

  • 1
    This looks very much like a menu structure and using Pathauto. – 4k4 Jun 1 '16 at 13:05
  • Do you know about any decent tutorial on how to achieve this with Pathauto? I know about the module but I only used it to automatically assign nice URLs based on the node title. Don't really need this to be in a menu (unless the menu could be used by pathauto to determine parent-child relationships). – Ondrej Jun 1 '16 at 13:25
2

I would set up a vocabulary, with a machine name such as site_nav,

then on your nodes, you would add a taxonomy term reference field to the site_nav vocabulary.

Then set up automatic path aliases using pathauto at /admin/config/search/path/patterns

You could use the title of the page or add an additional field, such as field_short_name to use in the url.

Then the pattern would be

[node:field_site_nav:url]/[node:field_short_name]

or

[node:field_site_nav:url]/[node:title]

or some such (I forget the exact pattern for urls of terms).

You could also use the content type names, if you have content types such as "products" and "about us", then the pattern would be

[node:content-type]/[node:title]

There are some more examples here:

https://www.drupal.org/node/1044980

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.