I have a parent page called 'Employment' that is a structure - it has 8 sub pages beneath it. I have just created a new single template and would like this to replace this page - is this possible?

Would really appreciate the help!

  • Your question is really confusing. You have a section with type structure and you created a new template file and would like to replace the current template file with the new one? Because templates are just files that are rendered into your pages (used by entries/categories) they can't replace them Oct 19 '17 at 13:51
  • I'm sorry - i'm really new to Craft. I have a page that uses a completely different design to the rest of the website so I created it as a single - is that the wrong way to do it?
    – Chris
    Oct 19 '17 at 14:00

As a more detailed reply to your comment:
You don't need to create a completely new section in order to have a different template. For Example when you create a section called 'Employment' you can have several different entryTypes in this section. In your /admin/settings/sectionsyou can see all your sections (left) and when you click on their entryTypes on the right you'll enter this page /admin/settings/sections/<sectionId>/entrytypes to edit them.

With the following folder structure you can do this:
for example your section is called pages and you have the entryTypes imprint and contact.

Your section template is /pages/_entry.twig

{% extends [
    'pages/_entrytypes/' ~ entry.type ~ '.twig'
] %}

so depending on your entryType the template for imprint or contact will be rendered.

In your case you would create a folder Employment and create different entryTypes for the different templates you want to render. In your Employment you render the template depending on your need. You can also extend your file to

{% extends [
    'pages/_custom/' ~ entry.slug ~ '.twig',
    'pages/_custom/' ~ entry.someCustomFieldValue ~ '.twig',
    'pages/_entrytypes/' ~ entry.type ~ '.twig',
] %}

so you can choose you template via slug/dropdown lists/checkboxes or whatever you want

  • Thank you for your detailed response! I'm not sure what to do as all the pages have already been set up in structures and given the name of 'pages' so if I start making changes to one it could break the whole website. I have inherited this website and trying to get my head around this.
    – Chris
    Oct 19 '17 at 15:02
  • Is there a way of changing an existing page's design to a new one without affecting the rest of the menu structure?
    – Chris
    Oct 19 '17 at 15:11
  • Not really.. You'll have to edit everything since your queries will change in all files. But that's way you are supposed to build websites in craft. You should build several different sections that group equal components. eg. pages with the entrytypes contact, home, imprint.... employees with the entrytypes boss, worker, typesetter, driver or the section vehicles with the entrytypes car, bus, train and so on... When you do this, you'll be able to query everything very smooth. {% set pages = craft.entries.section('pages') %}will give you all pages you can loop to build your menu Oct 19 '17 at 15:21
  • For Example this is one of my recursive menu macros pastebin.com/27FNH3NF in order to build all the menus on this page baunach-allianz.de (I'm not responsible for the content) Oct 19 '17 at 15:28
  • Thank you. I'm not too sure where to go from here really. I'm not sure if this article answers it: craftcms.stackexchange.com/questions/16249/…
    – Chris
    Oct 19 '17 at 16:01

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.