Skip to content

Commit

Permalink
fix global data accessing in layouts vs components
Browse files Browse the repository at this point in the history
  • Loading branch information
ooloth committed Jun 1, 2023
1 parent 8432826 commit 3bc84c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/_includes/components/meta-title.webc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<!-- see: https://11ty.webc.fun/recipes/webc-inside-your-head/ -->

<script webc:type="js" webc:is="template">
// see: https://11ty.webc.fun/recipes/webc-inside-your-head/

// If the current page's frontmatter includes a "title", put it before the site title
// Must access data via $data in components (but not in layouts or top-level pages)
// See: https://github.com/11ty/webc/issues/152
const metaTitle = title ? `${title} | ${$data.site.title}` : `${$data.site.title}`

;`<title>${metaTitle}</title>`
Expand Down
2 changes: 1 addition & 1 deletion src/_includes/layouts/main.webc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ layout: layouts/root.webc
<a href="#skip" class="visually-hidden">Skip to main content</a>

<header>
<a href="/" class="home-link">{ $site.title }</a>
<a href="/" @html="site.title" class="home-link"></a>

<!-- Read more about `eleventy-navigation` at https://www.11ty.dev/docs/plugins/navigation/ -->
<!--
Expand Down

0 comments on commit 3bc84c6

Please sign in to comment.