HTMX + Flask: Modern Python Web Apps, Hold the JavaScript Transcripts
Chapter: Course conclusion and review
Lecture: Jinja-partials package

Login or purchase this course to watch this video and the rest of the course contents.
0:00 One of my favorite things to come out of this course is the partials package.
0:04 Remember we did render_partial, and we would give some small part of HTML and some
0:08 additional data right inside of one of our HTML templates.
0:12 I really like this because even if you're not doing htmx,
0:15 it's a really cool way to break apart a huge,
0:18 complicated template into small building blocks.
0:21 Just like you would not really want to write a 1000 line long function,
0:26 it would be way better to write 10 100 line ones or maybe even more short
0:31 ones. It helps you understand what's going on.
0:33 And these partials both add to reusability, as well as to maintainability along those lines
0:39 So really useful in general. Now it's especially important as we saw in
0:45 htmx because so often we want to show the whole page and the page might
0:48 contain some HTML, and then based on the server interaction,
0:52 the server needs to return in another instance maybe with other data,
0:56 basically a subset of that HTML again.
0:59 And that's exactly what partials let us do over and over throughout this course.
1:04 Just to remind you, let's do one quick review of using one of these partials.
1:08 By installing the package, and then at the app startup we have to say
1:13 jinja_partials.register_extensions, pass it the app.
1:16 And then magically, well through the magic of Flask and Jinja,
1:20 this render_partial function will be globally available within all the Jinja templates.
1:25 So here we just use double curly to say take whatever text you get and
1:29 put it out here, and then we call render_partial,
1:32 give it an HTML link to a partial.
1:35 Here we have videos/partias/add_button.html.
1:38 Of course contained in the template folder.
1:41 And then we pass along the data.
1:42 Like here we have the data we're working with, which is a category that has a category
1:47 field. What the template needs, what the partial needs is something called cat_name.
1:52 So we say cat_name equals that value.
1:54 Just like a function call, and then when we call render_partial,
1:57 It's going to go to this add button HTML and here you can see the data
2:01 being passed from the outer template down to the inner template.
2:05 Really nice and reasonable. Basically functions for templates.