Persistent layouts and named slots #129
Replies: 13 comments 2 replies
-
Couldn't you just do... <template>
<layout title="Dashboard">
<template v-slot:title>
<div>
Content for "title" slot...
</div>
</template>
<div>
Content for default slot...
</div>
</layout>
</template>
<script>
import Layout from '@/Shared/Layout'
export default {
components: { Layout }
}
</script> |
Beta Was this translation helpful? Give feedback.
-
Yeah, I could, but then it's not anymore a persistent layout (see https://inertiajs.com/pages#persistent-layouts) and will get re-rendered on every navigation. |
Beta Was this translation helpful? Give feedback.
-
I would also love to see this. 👍 |
Beta Was this translation helpful? Give feedback.
-
Seems like this isn't so easy to implement. But there is a workaround I can live with. |
Beta Was this translation helpful? Give feedback.
-
Any work on this? I would use the workaround in https://github.com/inertiajs/inertia-vue/issues/129#issuecomment-640848129 but I swap my layout depending on if the page is a frontend page or admin panel page, so hardcoding a layout isn't gonna work. |
Beta Was this translation helpful? Give feedback.
-
Related: #171 |
Beta Was this translation helpful? Give feedback.
-
Any Progress on this? it's getting more and more tricky to implement slots. |
Beta Was this translation helpful? Give feedback.
-
I found a solution to get this work using transform function in vite plugin. https://gist.github.com/maksymsh/0fee0e46f2d1a2b0a709b450da87c9f2 |
Beta Was this translation helpful? Give feedback.
-
i was able to find a crude work-around that works for me but it is not really a valid fix: app.js inside of createInertiaApp:
example layout:
page:
component:
|
Beta Was this translation helpful? Give feedback.
-
I know this thread is old, but I ran into this problem today. A solution (for Vue 2 at least) I came up with is using a render function:
The You can pass to the slot whatever you want: simple text, or other Vue components. You just need to do it using |
Beta Was this translation helpful? Give feedback.
-
It's 2024, is there any fixes or work around there yet? |
Beta Was this translation helpful? Give feedback.
-
I have this setup since 2022, and its working fine for years for all I need without needing to modify anything for every type of setup Inertia setup createInertiaApp({
title: (title) => `${title} - ${appName}`,
resolve: async (name) => {
const page = await resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue'))
try {
const lt = page.default.lt && await resolvePageComponent(`./Layouts/Persistent/${page.default.lt}.vue`, import.meta.glob('./Layouts/Persistent/*.vue'))
page.default.layout = lt.default
} catch(e) {}
return page
},
.
.
}) Layouts location at <template>
<div>
<Banner />
<div class="min-h-screen bg-gray-100 default-layout">
<TopNav />
<header v-if="$slots.header" class="bg-white shadow">
<slot name="header" />
</header>
<main>
<slot />
</main>
</div>
</div>
</template>
<script setup>
import Banner from '~/Components/Banner.vue'
import TopNav from '~/Elements/TopNav'
</script>
<template>
<Head :title="$page.props.title ?? 'Page'"/>
<main class="py-5">
<div class="max-w-7xl mx-auto sm:p-3 overflow-hidden">
<slot />
</div>
</main>
</template>
<script setup>
import { Head } from '@inertiajs/vue3'
</script> Then for actual pages, I just use <template>
<div class="p-4">
Uses front-end layout
</div>
</template>
<script setup>
defineOptions({
lt: 'Frontend'
})
</script> |
Beta Was this translation helpful? Give feedback.
-
I've tried the teleport & it's working, you can check it out. @manuelteuber @hind-sagar-biswas main.ts
MainLayout.vue
Page.vue
|
Beta Was this translation helpful? Give feedback.
-
Is it possible to have named slots with persistent layouts?
Example:
Layout.vue:
Dasboard/Index.vue:
If I try this approach, even the default slot stays empty. If I remove
<template v-slot:title>
from Index.vue, the default slot gets rendered.Beta Was this translation helpful? Give feedback.
All reactions