My entries within specific section can be related to each other using "Entries" field.

If entry1 "Entries" field is filled with entry2, i want to entry2 url look like this:


How can this be acomplished?


Your will need to set up a route for the entry1 section.

For example, if your entry1 uri is looke like entry1section/{slug}, and your template is like "_entry1section/index" then the route would be

entry1section/{slug}/* to "_entry1section/index"

Then in the template, using

{% set lastSegment = craft.request.getLastSegment() %}
{% set all_slug_in_entry1_section = someFunctionToRetrieveSlug() %}
{% set all_slug_in_entry2_section = someFunctionToRetrieveSlug() %}

{% if lastSegment in all_slug_in_entry1_section %}

  {# means your request url is {siteUrl}entry1section/{slug} #}
  {# display the content from entry1 #}

{% elseif lastSegment in all_slug_in_entry2_section %}

  {# means your request url is {siteUrl}entry1section/{entry1-slug}/{entry2-slug} #}
  {# display the content from entry2 #}

{% else %}

  {% redirect '404.html' %}

{% endif %}
| improve this answer | |

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.