Skip to content
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

Use a .vue file as an Eleventy Layout. #5

Open
zachleat opened this issue May 22, 2020 · 2 comments
Open

Use a .vue file as an Eleventy Layout. #5

zachleat opened this issue May 22, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@zachleat
Copy link
Member

zachleat commented May 22, 2020

e.g.:

<template>
  <html lang="en" v-html="content"/>
</template>
<script>
export default {
  props: {},
  components: {}
}
</script>

and then referenced in the page template:

---
layout: "layout.vue"
---
@zachleat zachleat changed the title Use a .vue file as a Layout. Use a .vue file as an Eleventy Layout. May 22, 2020
@zachleat
Copy link
Member Author

zachleat commented Apr 4, 2021

Test already in the repo for this one. Vue as Layout file (Issue #26)

@notcome
Copy link

notcome commented Jun 6, 2022

Why is this an issue here? It seems to me that simply cutting away certain code from the plugin enables this functionality, at least partially.

Disclaimer: I am new to eleventy, with a week of experience, and has no previous experience in Vue toolchain at all.

First of all, I tried to place a Vue SFC file inside the layouts folder, which looks like this:

---
layout: layouts/base.njk
---
<template>
  <div class="vue-work-here" v-html="content"/>
</template>
<script>
export default {
  props: {},
  components: {}
}
</script>

It is identical to the one you posted above. Referencing this template from a Markdown and everything just works. I got the following output:

<div class="vue-work-here"><h1>About Me</h1>

<time datetime="2022-06-06">06 Jun 2022</time>

<p>I am a person that writes stuff.</p>

</div>

The next thing I tried is to use Vue with another base layout, which by the way is said to be supported in the README:

---
layout: layouts/base.njk
---
<template>
  <div class="vue-work-here" v-html="content"/>
</template>
<script>
export default {
  props: {},
  components: {}
}
</script>

Nothing happened. It seems that this plugin just ignores the YAML directive.

So I dug down a little bit in the plugin. When registering the new template format, I noticed that someone passed the following line:

read: false, // We use rollup to read the files

My guess is that this line stops eleventy to parse the file themselves and perform layout composition. So I just delete that line, along with this conditional statement:

if (str) {

And everything just works. I can use Vue as a layout and reference other base static layout that provides things like the basic html structure. Is there anything wrong with this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants