HTMX + Flask: Modern Python Web Apps, Hold the JavaScript Transcripts
Chapter: HTML template partials
Lecture: Concept: Using partials
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Quick concept review of using partials to show our add video
0:04
UI. So remember, we installed the jinja_partials package.
0:09
We registered extensions which makes the render partial function available on every Jinja template.
0:16
And then we just say here is an HTML file and here's the data it needs.
0:20
So in this case we wanted to show that add_button,
0:23
that partial HTML to add the button. And that thing has a piece of data it
0:28
requires, called cat_name. We had that same information but not in the same
0:34
variable. So we can just like you would with a parameter and a piece of
0:38
data you just set the value, and you pass it over variable name and the functions
0:43
argument or parameter name doesn't have to match.
0:46
All right. So that's what we're doing.
0:47
We say cat_name = category.category.
0:51
And then down in the add_button.html we just write our code in our
0:56
HTML that we would have put there and use the data that's passed over.
1:00
So we're going to add a hyperlink with hx-get and swap and the add a video
1:04
button or the add video hyperlink.
1:07
And then you can see we're using cat_name because we're going to have to propagate
1:10
that back as part of our htmx exchange. That cat_name is being used right
1:17
there. So we just use keyword arguments to specify the data that the partial needs, couldn't be simpler