Much of the time I only need to apply a specific layout to a single page, for example a REST API doc page or a Login page. Thus far I’ve been doing that in a way that feels kind of janky to me, and I was hoping to fiind a better way. Here’s my approach in a few steps:
Add a pagetype param to that page:
---
"title": "Login"
"pagetype": "login"
---
Create a special partial for that page (in layouts/partials/login.html):
<main>
<h1>Login</h1>
<!-- logic specific only to the Login page -->
</main>
Create an if/else logic in _default/single.html that renders based on page type:
Maybe I am missing something, but why don’t you assign a new type to the login page and then create its own specific layout?
Types can be assigned in two ways:
Directory structure. For example everything in content/post is of type post. Content in content/login/ is of type login.
Through the type parameter in front matter which overrides number 1. For example: type: login. In this case the content file can be anywhere in the content directory.
Then this page will use the template in layouts/login/single.html.
If you want to give the page a specific URL then you can specify the URL in the front matter too. url: "/login/" will put it at http://basurl/login/.