question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting the frontmatter in sveltekit __layout.svelte

See original GitHub issue

I tried using an mdsvex layout and not using one, in both cases the default __layout.svelte in the folder cannot access the frontmatter from the document.

Is there a way to pass it from the mdsvex layout (blog_layout.svelte) to the default __layout.svelte?

I’m kind of a beginner in svelte so I don’t know if there’s an easy svelte-level solution for this. I tried setContext() from the mdsvex layout and getContext in the default layout, but that didn’t work because __layout.svelte runs first.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
reesericcicommented, May 11, 2022

@zmre Is there any way to have mdsvex add this script tag to every page with front matter?

<script context="module">
    export async function load() {
        return { stuff: metadata }
    }
</script>
1reaction
zmrecommented, May 27, 2022

I expect you’re right about them needing to replace it with something that can serve a similar purpose if it goes away.

I think context only works within a group of components in the hierarchy and doesn’t work for flowing up to layouts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Frontmatter with MDSVEX
You can level up with Svelte Kit right now! Purchase individual course. $. 49 .99. Add To Cart. Become a Pro and unlock...
Read more >
Advanced routing • Docs • SvelteKit
Like pages, layouts can themselves break out of their parent layout hierarchy, using the same technique. For example, a +layout@.svelte component would reset ......
Read more >
I use vite-plugin-svelte-md, how can I get access to frontmatter ...
Hello, I setup vite-plugin-svelte-md with success in a SvelteKit project…
Read more >
Using mdsvex with SvelteKit (Markdown + Svelte!) - YouTube
Markdown is nearly ubiqitous when it comes to blogging. Many applications use it for nicely editable files. With the mdsvex library, ...
Read more >
Blogging in SvelteKit | CloudCannon
Getting set up in SvelteKit · Layouts in SvelteKit · SvelteKit Components ... which will be set through front matter in our post...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found