Jinja is a great templating language that’s used with python. One of the easiest ways to not repeat yourself in Jinja is to use macros.
Let’s say you want to build a blog. You might have something like this
You might try to use for loops and variables in Jinja:
A little bit of repetition, which can get annoying if you want to add a date:
At this point even I’m getting tired of contriving these examples. Enter the
macro. Macros can appear anywhere in your template. They don’t render unless
they are called so I usually stick them at the veryt top of a page:
That’s a lot easier. You can think of macros in templates the way you think of functions elsewhere.