FREELessons: 15Length: 1.6 hours

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

3.3 Set Up the Page Entry Type and Template

Hey, welcome back to Build a Blog with Craft CMS. So far we have finished creating everything that you need in order to run the actual blogging part of the blog. Now we're gonna add something else that's really common in popular blogging platforms, and that is the ability to create static pages. So by now you're probably fairly familiar with the process of creating different types of entries. And we're just gonna go through that same thing again. And we're gonna create a template to go along with it. So we're gonna jump into Settings. And we're gonna create a new section. So this one is gonna be called Page. So we'll go ahead and hit the New section button. And we'll fill in the name. We'll use the autocreated handle. This time, rather than using a Channel section type, we'll want to use a Structure section type. So we're not going with the channel because a channel is designed to allow you to create a stream of ongoing updates. We're not going with a single because when you create a single section type, that's appropriate if you're only gonna create one single entry. We want multiple pages and we wanna be able to potentially structure them with things like sub pages with one nested under another. So, we're gonna go with the Structure section type. Now we'll just scroll down and have a look at the entry template information as well as the entry URL format. And basically we're just gonna leave all of this at the default, everything is fine just how it is. And we just pay attention here that when we wanna create our template, it's gonna need to be in a folder name page. And the name of the template is going to need to be _entry. So we'll go ahead and save that. Now that has automatically created a page entry type for us. And we don't need to change the name or the handle. They're fine as is. What we need to do is set up our field layout. So we'll hit New Tab. We'll just call this Page. And then the only field that we need to add Is a body field. We already have the title coming from this automatic title section, so that'll give us that basic title and body format that you most commonly see on static pages for blogs. So go ahead and save that. Now let's add a couple of new entries under our new Page Entry type. So we've got Pages here under Structures. So we'll make a new one. An example page, just add in some placeholder content. And now let's make another one. I'm gonna set this up as an example sub page. And with this one we're gonna drag it over and underneath here to make that a child. And you can also select a parent when you're creating the page. So now we've got our page entry type and we've got a couple of pieces of test content. Now all we need is a template. So we're gonna jump into our Templates folder. And you recall we said that the folder we needed to use was one named Page, and that we're gonna need a template named _entry. Now here our entry template needs to be fairly similar to the one that we're using the single blog posts. All we'll have to do is just remove a couple of things like the featured image and the categories. So we're going to go into our Blog folder, copy the entry template, place it into the Page folder, and open it up for editing. As always, we'll turn on our syntax highlighting. And now we can just delete the stuff that is needed for blog posts that's not needed for static pages. So we don't need a featured image, we don't need to show categories and we don't need a post date. And then we're gonna do just one more thing and that is change the class on our heading from entry_title to page_title. All right, so now let's check out what we've got. So you can just click on one of these links here to view any entry straight from the dashboard. And there is our page. So we've got our heading and we've got our body. So everything is exactly as we expect it to be. So you've probably noticed at this point that there's something fairly significant missing from the site, and that is the content of our top bar that we have here. We're gonna fill it in with two things. We're gonna have a search bar that's gonna appear on the right here. And we're gonna have a nav bar that's gonna be automatically populated with our pages, like the two we've just created, and with our category names. So in the next lesson, we're gonna kick that process off by adding the search bar in the right-hand side of our top bar here. So I'll see you in the next lesson.

Back to the top