I have a content type that requires different views. I am defining multiple view modes in the content type manage display page and using view page mode. This works fine if the url is /%/{view mode} as defined in the view page module. However, we would like the view's url alias to be a custom alias.

Default view alias: /subpath/[node:title] (Pathauto pattern) View 1: /%/myview which translates to /subpath/[node:title]/myview (View Page Mode)

We'd like /%/myview to have its own alias like /mysubpath/[node:title] .

From what I understand, Pathauto alias works only with default views. How can I make this happen?

  • 1
    See drupal.stackexchange.com/questions/59690/…. I bet you can either choose a view mode based on the URL, or maybe the module mentioned there will help you.
    – beltouche
    Mar 4, 2020 at 20:24
  • I think the problem is related to canonical urls. I have two aliases for same nodeId: /subpath/{arg} -> /node/{nodeId} /second-subpath/{arg} -> /node/{nodeId}/online Where /node/{nodeId}/online is defined in ViewMode Page as /%/online. By the time the hook_entity_view_mode_alter is reached, the url alias for the alternative view mode has already thrown a 404. The view mode does indeed get changed, but the page has already thrown the 404. In the URL alias, Mar 9, 2020 at 18:49
  • Sounds to me then that what you really need is to get the two URLS to point to the same node. Put the View mode aside for a bit. Once you know that that works, you can use hook_entity_view_mode_alter to key off the request URL to pick a view mode for the node..
    – beltouche
    Mar 9, 2020 at 19:08


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.