Creating a custom template for blog posts
Figure 4.2 – Final blog post layout
We could continue to use the base template for our site on the blog posts, but we now have unique data for each page. We could set up conditionals on the base template to handle these, but if we want to create something starkly different from the base layout, it would become a mess of nested if
statements.
To set up a new layout, create a new file in the src/_templates/layouts
directory named post.html
. From there, we need to refactor our base layout to use includes for the standard HTML. This will allow their reuse in the post layout.
Refer back to Chapter 1 and try to set this up on your own as a challenge.
If you’re not ready for that, we need to create header.html
and footer.html
files in the /src /_templates/includes
directory. The header file will contain everything from the Doctype
to the main div
element that will contain the content of each page:
<...