Chapter: HTML template partials
Lecture: What do you mean by partials?
0:00 "Click to Edit" was super cool, wasn't it? But it started to reveal a problem that Flask by itself is not
0:08 well designed to deal with. That is, we need to show the entire page with some element of HTML, and then we need to show a partial part of that page or
0:19 just that fragment of HTML again in a different view. Remember we had that ads button to add a video which would then reveal the form?
0:28 We had to have that in two different locations and that's clearly error-prone and not a good idea. So what we're gonna do in this chapter is take a
0:36 little diversion and talk about an open source package I created for Flask and really any library that uses Jinja called Jinja Partials.
0:46 Now, Jinja Partials is kind of like adding functions to HTML. We can go to any part of our template,
0:54 pass it along data to one of these sub templates and it will render inside of that
0:59 template as well as being able to treat that piece completely separately and isolated and return
1:05 it back directly from a view for the htmx interaction side of things.
1:09 Some people think this is similar to Jinja's include or sometimes Jinja's macro features.
1:17 It's definitely not the macro feature, that's completely different. This has a whole new feature,
1:23 like include, it is similar, but it has more functionality to structure the way the data is passed over to sub templates.
1:30 So I think it's pretty unique, and it's going to generate incredibly clean code on the
1:36 HTML template side. It allows to reuse it exactly the way we need to for htmx. We're not gonna do htmx in this chapter yet.
1:44 That's the next one. But this is the groundwork to having clean code with htmx