-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can i use slots in layouts? #63
Comments
Oh I would like that, I used the similar feature in Nunjucks. I will try it later to see if it works. |
@zachleat any recommendations or workarounds about this? |
The clearest workaround for now is to bypass Eleventy layouts altogether and use a WebC component instead. <my-base-layout>
<link slot="meta" rel="stylesheet" href="assets/css/home.css">
</my-base-layout> Another less documented method is to use the <script webc:type="js">
webc.helpers.html(`<link rel="stylesheet" href="assets/css/home.css">`, "meta")
</script> where the second argument <!-- layouts/base.webc -->
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta webc:nokeep @raw="getBundle('html', 'meta')"/>
</head> |
I've landed on the following. Have included some extra flavour re: how I'm handling titles, as it might be helpful if you're working on <!-- _components/site-head.webc -->
<script webc:setup>
const metadata = {
title: 'Default title',
description: 'Default description',
};
function setTitle(title) {
return title ? `${title} — ${metadata.title}` : metadata.title;
}
</script>
<meta charset="utf-8" />
<title @text="setTitle($data.title)"></title>
<meta name="description" :content="$data.description || metadata.description" />
[etc...] <!-- _layouts/base.webc -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta webc:nokeep webc:is="site-head" />
</head>
<body>
[etc...] <!-- index.webc -->
---
layout: base.webc
title: This will be prefixed to metadata.title
---
Hello world. Let me know if that helps :) |
Can i use slots in layouts like in this way?
The text was updated successfully, but these errors were encountered: