Layouts
Wrap your pages in reusable layouts.
Layouts are like picture frames for your content. They wrap around your page content and give it structure - headers, footers, sidebars, whatever you fancy.
Creating a Layout
Layouts live in the layouts/ folder and are always HTML files. Here's a simple example:
layouts/default.html
<article class="page">
<header>
<h1>{{ title }}</h1>
<p class="meta">{{ date }}</p>
</header>
<main>
{{ content }}
</main>
</article>
The magic happens with {{ content }} - that's where your page content gets inserted. You can also use any front matter variables like {{ title }} or config values like {{ sitename }}.
How Layouts Are Applied
Swifty uses convention over configuration (borrowed from Ruby on Rails) to automatically pick layouts:
- Folder-matched layouts: Pages in a folder called
blog/automatically uselayouts/blog.htmlif it exists - Default fallback: If no matching layout exists, pages use
layouts/default.html - Explicit override: Set
layout: specialin front matter to uselayouts/special.html
This means you can create different looks for different sections without configuring anything. Just name your layout file after your folder!
Choosing a Specific Layout
Want a page to use a particular layout? Just say so in the front matter:
---
title: My Special Page
layout: fancy
---
This page will use layouts/fancy.html
Going Layout-Free
Sometimes you want full control. Set layout: false to skip the layout entirely:
---
layout: false
---
<div class="custom-page">
This content won't be wrapped in any layout.
</div>
This is handy for landing pages or anything with a completely custom structure.
Nesting Content
Layouts are applied after your Markdown is converted to HTML, so you get the full formatted content. The flow goes:
- Your Markdown page is parsed
- Front matter variables are extracted
- Markdown converts to HTML
- Layout wraps around the HTML
- Template wraps around everything
It's layouts all the way down!