Chapter: HTML template partials
Lecture: Concept: Using partials
0:00 Quick concept review of using partials to show our add video UI. So remember, we installed the jinja_partials package.
0:10 We registered extensions which makes the render partial function available on every Jinja template.
0:17 And then we just say here is an HTML file and here's the data it needs. So in this case we wanted to show that add_button,
0:24 that partial HTML to add the button. And that thing has a piece of data it requires, called cat_name. We had that same information but not in the same
0:35 variable. So we can just like you would with a parameter and a piece of
0:39 data you just set the value, and you pass it over variable name and the functions argument or parameter name doesn't have to match.
0:47 All right. So that's what we're doing. We say cat_name = category.category. And then down in the add_button.html we just write our code in our
0:57 HTML that we would have put there and use the data that's passed over. So we're going to add a hyperlink with hx-get and swap and the add a video
1:05 button or the add video hyperlink. And then you can see we're using cat_name because we're going to have to propagate
1:11 that back as part of our htmx exchange. That cat_name is being used right
1:18 there. So we just use keyword arguments to specify the data that the partial needs, couldn't be simpler