0

This is probably very straight forward but unfortunately I can't seem to solve it.

We want to create a dynamic URI structure that allows us to easily create pages and link them with parent directories. So basically we have 4-5 pages that need to be added as "singles". Then we have around 40 pages (with around 3-4 total layouts) that we don't want to create a "Single" for each. So we've created a "Structure" called Pages and inside have 3-4 entry types. Grid list, plain template, big image and small image. We just want to create a bunch of "pages" and specify the parent URI.

For example, we have a single "Our Company", but then inside that parent we have multiple pages which we want to add in the "Pages" structure. But as our Entry URI for "pages" is set to {slug} this URL is www.website.com/slug. We need it to be www.website.com/our-company/slug. Of course we can simply update the Entry URI to have "our-company" but this won't work as all of the Entry URI's for all 40 pages will be our-company.

So basically, how can we manually or dynamically specify the segment 1 that page's URI should be?

1

Not sure I'm following 100%, but in Craft 2, a structured section has a "Nested Entries" text box in the "Entry URL Format" under a section's settings where you can dynamically access the URI of a parent element in a structure like so:

{parent.uri}/{slug}

In Craft 3, under a section's Settings, that has moved to "Site Settings" and you just have the "Entry URL Format" text box. You could do something similar like so:

{parent.uri ?? ''}/{slug}

i.e. if there isn't a parent.uri, just use the slug, otherwise use prepend it.

You've got the full power of Twig in those text boxes, so you can adjust however you need.

  • Thanks Brad. However, I don't think I explained myself properly. Let's say I have 3 singles. Our Company, What We Do & Projects. I want to be able to place Pages (structure) to use those singles as a parent URI. So if I create 4 Pages for our company I need to prepend those with /our-company/page-name and if i create pages for What We Do – I need those to be prepended with /what-we-do/page-name etc... I'm just struggling with how to do this. Basically, I don't want to create 20+ singles for every page. I would rather use a pages structure with multiple entry types. – James N Nov 21 '17 at 9:23
  • Why keep them as singles and not just make the "root" nodes in a structure section? They can still have multiple entry types. – Brad Bell Nov 23 '17 at 1:50

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.