3

I have an existing ExpressionEngine site which I'm looking at moving to using Craft instead.

Only really had a quick cursory glance at the system so far but a little confused on a few things.

Say I have top level menu with items such as

Home Services Company

For instance let's say in the services menu there are some subpages such as :

Service 1 Service 2

and so on and so forth. On the existing site we are using the Structure module which allowed each of those services to have a url such as :

http://www.mysite.com/services/service_1

and so on. That's all fine so far as long as each item in that menu is a service. Now let's say for arguments sake that we want a standard informational page thrown into that menu. From what I see so far with Craft (really hoping I'm wrong on this though) if I create say an information section and then link to that in my navigation then I'm going to end up with something like:

http://www.mysite.com/information/my_information_page

What I'd like to end up with however would be :

http://www.mysite.com/services/my_information_page

This makes more sense to me with the menus and URLs for people to remember.

I know I must be missing something obvious here but just not quite seeing what yet?

The above is just a very literal example but the whole site is like this in that the subsections can contain any kind of content but they still follow a good URL scheme.

Thanks in advance for any help with this.

Best wishes,

Mark

3

I think you're looking for entry types - when you open a new 'services' entry you could pick from "service" or "service-information" entry types. Each entry type has it's own field layouts.

This would mean your URLs can follow the same structure without writing new routes etc.

  • 2
    Hiya, thanks for the answer. I'm not sure this is going to work though as I would definitely be having information pages all throughout the navigation hierarchy and so using entry types I would need to have a Services Information type, a Company Information type and so on and so forth. Not sure if entry-types can be shared between sections or not so if they can't then that would mean me having to repeat a lot of creation of fields and so on. Unless there's a way around that at all? – Mark Bowen May 16 '15 at 18:36
  • 1
    No, entry types can't be shared across sections. Even if you found yourself having to add identical "Information" entry types to all sections, you wouldn't have to repeat field creation, though – fields can be shared across sections and entry types. You'd only have to repat field layout creation, which is a much simpler process (especially if you're smart about your field groups). – Mats Mikkel Rummelhoff May 16 '15 at 21:48
2

The closest thing to EE's Structure module in Craft would be to build your site using a single Structure section w/ multiple entry types, and to set the URL format for that section to {parent.uri}/{slug}.

AFAIK, this is the only way to achieve both a site-wide, global hierarchy encompassing all content, as well as a uniform, hierarchical URL format for any content type.

Obviously though, dumping all your content in a single Section might not be ideal (depending on the complexity of your site).

Another approach – and this is the one I'd recommend – would be to create a separate "Navigation" or "Site structure" section with an Entry field (or use a plugin like A&M Nav or Menus, which basically does the same thing but with more specific UI).

Obviously, this approach means that creating content and adding content to the site's navigation/structure hiearchy is a two-step process. This approach also doesn't solve your URL issue, as the structure you build for your "Navigation" structure won't carry over to its linked entries. I'd recommend letting that slide, but if you're determined to go the extra mile, you could possibly hack it like this:

  1. Set the "Navigation" section's URL format to {{parent.uri}}/{slug}, and add a template – navItem.html – to it.
  2. Output your nav using the nav items' URI and not the linked entry's URI for the href attributes – i.e. you'll treat your "Navigation" entries' URIs as your entry permalinks
  3. In the Navigation section's template – where all requests to the Navigation entries' URIs will end up – do something like this:

navItem.html

{# Cache the nav item entry to another variable #}
{% set navEntry = entry %}
{# Cache the linked entry to the "entry" variable (this assumes your Entry field for the Navigation section has the handle "linkedEntry" #}
{% set entry = navEntry.linkedEntry %}

{# Use a switch statement to include a different template based on the linked entry's section #}
{% switch entry.section.handle #}
    {% case 'services' %}
        {% include 'entry.services.html' %}
    ...
{% endswitch %}

Pretty cumbersome, and a hack for sure – but the effect would be that you'd have contextual, hierarchical URIs, whilst still retaining your content in separate sections.

I realise neither of these approaches are ideal, but right now I'm pretty sure those are your best options.

  • Hiya. If I set two sections to have the same URL format then I believe I'd still have the same problem as above wouldn't I? I would need these information pages in many different sections of the navigation and also different types of pages such as forms or maps and so on and so forth so if they pointed to services then that's not going to work for say the Company page. I'm sure I'm missing something obvious here but would really love to get things working pretty much the way they did with the Structure module in ExpressionEngine as that was a really nice way of working. – Mark Bowen May 16 '15 at 18:39
  • Hello @MarkBowen – I interpreted your question to concern URLs, specifically. I just edited the answer to address what I now believe is your primary concern, i.e. how/if you can replicate EE's Structure module's behaviour in Craft. – Mats Mikkel Rummelhoff May 16 '15 at 21:32
  • Hiya. Thanks for the help and the code. I'll try this out as soon as I can. Just wondering though what other people do in this sort of situation though? You mentioned 'letting it slide' so wondering are other people's clients okay with URLs that don't 'truly' reflect where a person is in the scheme of the site? I just always thought that it's best to have URLs that are not only easy to remember but also reflect the page you're on for SEO purposes too or is that not such a big concern any more? – Mark Bowen May 18 '15 at 8:15
  • URLs are still important, for sure, though having a 1:1 relationship between your content and the presentation layer might be a little out of date - or at least a model neither EE nor Craft is really committed to, Structures aside. Personally I never really battle w/ your dilemma - the design/architecture of the site obviously matters, but I usually find that as long as that part is fairly well thought out, the URLs flow quite naturally. – Mats Mikkel Rummelhoff May 18 '15 at 9:24
  • Usually, I'll put completely separate content in their own channels, and build the main nav separately using a Structure (or automatically in the template). Entry types, URL formats, relationships using Entry fields and the concept of modular design (using Matrix fields) are also important structural building blocks. It's difficult to give solid advice without knowing more about your project, but note that there's nothing inherently wrong w/ e.g. using a single Structure and many entry types, if that's what the design requires. It could get a little unwieldy, but so can an EE Structure :) – Mats Mikkel Rummelhoff May 18 '15 at 9:32

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.