Client Created Pages in Craft CMS

December 21, 2015

Today I was tasked to create two new templates for a career website that had recently launched. The client wanted to have the ability to create new pages instead of having to come back to dboy (the agency I contract for) to create the new pages. This is not an unusual scenario in the client services world. But it was unusual for the typical clients that I build websites for contracting for dboy.

The site was built in Craft CMS. I started using Craft earlier this year. It is my favorite of the CMS solutions that I have used (WordPress, Drupal, and ExpressionEngine being the others).

If It Were WordPress

If I was building this site in WordPress, this problem would have been pretty easy for me to solve. I would have created a specific template matching the layout of other pages on the site. Then I would have given instructions for the client that when they created a new page, to select this custom template from a select dropdown menu in the WordPress admin.

wp-templates
Template dropdown example from project I built this summer.

But Craft Works Differently

But as I looked to tackle this problem in Craft, there is not a similar solution. Craft has different ways of creating “pages” with Section types. Normally when creating one off pages, I would use the Single page type. I have used the Channel type for things like blog entries or events. And I am currently using the Structure type on this client site for an About section that contains 6 subpages.

Screenshot of Structure Type selection when creating a new “Section” in Craft CMS.

It was not immediately apparent to me how to solve my problem. Channel types did not seem to fit what I needed (I had wrongly assumed that that url structure would be something like channel/page-title).  And I did not need a specific order so Structure did not seem to fit. That left me with only Single pages as a possible solution. Because of the way Single pages are created, this solution would make it more difficult for the client to create new pages. (I like simple bulletproof solutions to make it as easy as possible for the client to create a new page).

For this solution to work, the client would have to define the fields that displayed in the CMS content entry page. It would have only been one field, a body field which is a Rich Text field. And then the client would have to follow my instructions to assign the correct template to the new page they created. They would have to type in the name of the template into a field in the CMS, not choose it from a dropdown like in WordPress.

Not a Bulletproof Solution

I was not crazy about this solution but it seemed to be the only way that I saw to solve my problem. There were too many places that if the client did not follow my instructions, they would run into problems creating the page themselves. This would just frustrate them and they would have to seek out help from dboy.

The best solutions are the ones that reduce the chances of error by the person using the software. There were too many potential places for error in the solution I had come up with. But I really did not see another way to solve the problem I was tasked.

So I created a test page, template, and added some styles that they might need to the stylesheet. As I began testing, I realized that the client would not be able to create a new Section type of Single. I had set up user privileges on the site so that the client would not have access to admin settings. In Craft, you can only create a new “Single” page with access to admin settings.

So now I was faced with a new dilemma. The only way to make my solution work was to give the client admin privileges. That creates a whole new set of problems and gives more opportunity for the client to “break” the site.

A Different Direction

I knew that I did not want to change the user privileges on the site so that caused me to explore a different solution. One of my early ideas was to use the Channel section type to create a Client Created Pages channel that they could add new entries to. As I have already mentioned, I had wrongly assumed that doing it that way would create another level in the url like example.com/channel/their-new-page.

I decided to create a new channel and low and behold, I could set the url structure to just be the new entry. This solution would be ideal for the client because I could set up the channel pages to use the template I had created and I set up how the entry form in the CMS looked. All they would have to do is create the new page and add the content. So much simplier and bulletproof.

Making It Even Better

When I was first assigned the problem, I was asked to create two different layouts for larger tablets and desktop, a full-width layout and a two-column layout that had a news and events module in the secondary column. Earlier in the day I had learned about the “lightswitch” field in Craft. It gives you a simple toggle input for a simple yes or no. I decided to use the field so that the client could “turn on” the two-column layout.

The lightswitch field as seen on the CMS entry page.

I then created a template with a conditional to see if the lightswitch field was true. If it was, I outputted the code for the two column layout. If not, the page got the full-width layout.

But One More Thing

The client also wanted the ability to add these new pages to a navigation menu in the footer. We already had one page on the site that was not part of the main navigation that only linked in the footer. My solution was to use the plugin Craft Menus by Familiar Studios. The client can create add their new pages to the menu and order them however they choose. I just added the two pages I already had in a secondary navigation. The plugin is easy to use and allow page links to be created by getting a list of pages in a popup and choosing it from the list.

Menu Creation Page – You create a new node
Popup that allow you to choose the page to link to for your menu item

4 Comments

  1. Sarah Evans

    March 16th, 2016

    Hi, Great article. Came across your article when looking at different ways to structure my sites. I tend to rely too much on Singles when creating sites in Craft which as you have touched on can cause problems.

  2. Reinhard

    April 1st, 2016

    Great! I faced the same problem like you. Thank you so much for this article.

  3. Jeff

    April 22nd, 2016

    Sarah, Thanks for the compliment. Glad it gave you some ideas on how you could do things differently.

  4. Terry Upton

    October 23rd, 2016

    Good article. Very helpful. One question though, what were your reasons for choosing a channel instead of a structure and perhaps having different entry types?