Adding a CMS to Your Pyramid Web App Transcripts
Chapter: The Pages
Lecture: Rendering the page within our site template
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
so far with our CMS route method, our view method here. What we've done is we said, we use your cool little view model idea
0:07
our view model pattern that's working super well and we're just going to double down on that.
0:12
But we said If there's a page, we're just gonna do something super silly like,
0:15
Say, here is the title. If there's a redirect. We're gonna redirect them. If there's no page and no redirect, we just say, "Not Found".
0:22
But what we want to do is what you just on that last picture, a beautiful page that looks like it belongs with the rest of the site.
0:28
So how do we do that? Well, that's more or less this thing I commented out over here. So we're gonna specify a renderer.
0:35
And instead of doing this, we're going to save 'view_model.view_dictionary'
0:47
This is close, except for we want this to be CMS, and we want this to be something meaningful, like Page.
0:47
Why my calling "page" and not CMS requests like the others. Well, we're only using it for the page scenario. This one, we're not using it.
0:54
And this one "404" we're not using it. So page, it's gonna be in my world. Now, let's go and create that over here.
1:02
You don't have a folder yet, but we will shortly. CMS And then remember the easiest way to get one of these
1:07
because they're not just from scratch pages, but in fact, they are based on this shared layout template. We want it to look like just just so
1:27
we're gonna do a copy in a paste and call this page.
1:20
Now, I'm gonna add one quick little CSS class here because this one we wanna have some space have padded.
1:26
And actually, I'll show you what that does anything about first. So we're gonna look at real quick without the padding. Kinda bad, actually.
1:35
If we go to about... Ah, it's centered, so you can't really tell, but basically.
1:40
Stuff goes to the edge. It goes right to the edge, which is not amazing.
1:43
So we're gonna put this little padded thing in here and it just has a little more room.
1:48
Most importantly on the sides. Like I said, you can't really see it this moment. Okay, so we're gonna put that into our page template over here
1:56
and then in this section, What are we gonna do? I just want to put the entire blob of text that makes up the page. Right?
2:03
Well, let's do it like this. How do you put text in pyramid? You say whatever the text value is.
2:10
So let's look at our view model because it tells us what is passed over. So right now we're passing a page. If you look at pages, they have a contents.
2:19
Looking at our fake data for the moment, we have a contents. However, as we grow this thing, we're going to actually want to
2:25
maybe have the content store to something like markdown and then generate HTML. So I'm gonna have a 'self.html = None'. And then if they'll stop page
2:41
something like that, where we get the contents and set them to this HTML because this is going to get really interesting and more powerful as we go.
2:48
Just kind of looking ahead. So what do we have to do over here in our little page template?
2:53
We have to put HTML all right, and we probably also want to set the title and were not able to do that yet?
3:00
Notice. We've got these cool little extra sections in the shared layout that weaken drop in
3:05
notice right here. We're defining a slot for additional CSS. Let's go do one for the title up here.
3:18
We'll call this 'htitle' or something to that effect. And if they don't fill it out, this should be there. Otherwise we can have that go.
3:27
All right, So, over here. We can actually put the title. Remember we have to specify the title. Let's do it like this.
3:40
That way we don't have to put title they can just put the words down here. So let's just say we had this. We had title, I believe, for our page.
3:47
Let's have a quick look. Yeah, title. So we can just set it up there, maybe even make it something like this 'PyPI:TITLE OF OUR PAGE'.
3:56
We don't need to send any of this, but this one, we're going to have page title. Is that what I called it, double check. Yes. Okay.
4:05
This is looking pretty good. Let's go over and make sure we're using it. We're using it. Let's give it a run and make sure everything's working.
4:14
We come over here we had two. These company history and company employees. It didn't love title did it? What was wrong with that?
4:21
Well, where does title live? Over here. It's not called 'title'. It's on the page, right so we can say 'page.title'.
4:31
Remember? Only gonna be in this page if there's on this template. If there's a proper page, here we go.
4:36
"PYPI: Company History". Super and then details about our history. And then we probably want to even go and put the title again up here.
4:44
Let's put like a "h1" like that. Here we go. Beautiful. Company history. Let's go to employees, our team, details about our employees.
4:56
This is looking pretty good right? Now we don't have anywhere to click.
4:59
Like if I click on help. That doesn't exist yet, sadly, but you can see our CMS.
5:03
It's controlling the title, putting this in here and then this is just gonna be arbitrary content,
5:08
not a big fan of it being centered, So we want to work on that in our CSS. But basically this is off to a really good start.
5:16
There's a few things we're gonna need to keep changing, as you'll see, as we get into it. To do real stuff,
5:21
but we're off to a good start showing our CMS content