Open mirisuzanne opened 2 years ago
Hmmmmmm, I’m having trouble reproducing this one—can you provide any additional context?
I see you’re using the markdown input files—does that mean you’re using the transform method?
I see you’re using the markdown input files—does that mean you’re using the transform method?
I don't know what this means, so maybe?
For context, I'm playing with this on my personal site (mirisuzanne/mia) which currently uses markdown & nunjucks for everything. I started by trying to convert some of the site/footer includes. Initially I was using the render plugin and nunjucks shortcode, but when I started running into errors, I created a new webc base layout that was only rendering the footer. Overall, this would be a helpful thing to cover that I don't see much in existing demos/docs - how to handle migrating from (or integrating with) existing template languages. (The lack of loops in webc makes it especially hard to migrate entirely at this point)
I can try again this weekend, and push a branch with a reduced test case, if that would be useful.
https://www.11ty.dev/docs/languages/webc/#post-process-html-output-as-webc
I created a new webc base layout that was only rendering the footer
This gives more clarity—though a WebC layout file still works for me. Are you saying that the WebC layout file worked but the Render plugin did not?
(If so…) this might be a duplicate of #16
I was getting these errors using both the render plugin and also the webC layout. I'll take a look again this weekend, and get you a reduced test case if I can.
I was not using a post-processing transform.
Ok, as discussed in person:
webc:type="11ty" 11ty:type="njk"
I've attempted with two different layout files. One is webc:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>WebC Example</title>
</head>
<body>
<main @html="content"></main>
<footer-test>hello</footer-test>
</body>
</html>
The other is nunjucks:
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>hello test</title>
</head>
<body>
<main>
{{ content | safe }}
</main>
{% renderTemplate 'webc' %}
<footer-test>hello</footer-test>
{% endrenderTemplate %}
</body>
</html>
Both are loading the footer-test
component:
<a :href="url('/who/')">link test</a>
<footer webc:type="11ty" 11ty:type="njk" webc:keep>
{% include "site/author.njk" %}
<a href="{{ '/who/' | url }}">link test</a>
<slot>default content</slot>
<div class="colophon">
{%- set year = null | date('year') -%}
{{ colophon | replace('@year@', year) | md | safe }}
</div>
</footer>
(I added those two link tests just to confirm that 1) global helpers are working, and 2) webc is compiling outside the nunjucks block.)
In both cases, the output HTML from the footer-test component is:
<a href="/who/">link test</a>
<footer 11ty:type="njk">
{% include "site/author.njk" %}
<a href="{{ '/who/' | url }}">link test</a>
hello
<div class="colophon">
{%- set year = null | date('year') -%}
{{ colophon | replace('@year@', year) | md | safe }}
</div>
</footer>
</body>
</html>
Woof, I found some HEFTY bugs with webc:type="11ty"
in #16, for which the fix is shipping with Eleventy WebC v0.7.0.
I’d hold off here until that is released!
It is released!
I’m trying to learn WebC by converting some of my existing Pug-based projects, and I’m having a rough time. :-/ I stumbled on this thread while looking for help.
@mirisuzanne:
eleventy-plugin-webc
? I have the following at the time of this writing:
@11ty/eleventy@2.0.1
@11ty/eleventy-plugin-webc@0.11.0
(which is using @11ty/webc@0.11.3
)Things have gone much better for me on a site I built from scratch with WebC and Nunjucks. It is also using the latest versions. I haven't tried porting my old site again, which is where I ran into this error.
I tried a few different patterns, with or without
this
:(I recognize that the
url)
function isn't doing much here. I mainly just wanted to try built-in functions to see if they would work better. I got the same results withslugify()
as well)also in
@html
using my ownmd
function:And with nunjucks inside
webc:type="11ty" 11ty:type="njk"
:In all these cases, the server fails to start:
webC syntax, `url()` helper
``` [11ty] Problem writing Eleventy templates: (more in DEBUG output) [11ty] 1. Having trouble writing to "_site/books/greenmud/index.html" from "./content/books/greenmud.md" (via EleventyTemplateError) [11ty] 2. url is not a function (via TypeError) [11ty] [11ty] Original error stack trace: evalmachine.njk-in-webC syntax, `date()` helper
``` [11ty] Problem writing Eleventy templates: (more in DEBUG output) [11ty] 1. Having trouble writing to "_site/tags/all/index.html" from "./content/tags/detail.njk" (via EleventyTemplateError) [11ty] 2. (unknown path) [11ty] Error: filter not found: md (via Template render error) [11ty] [11ty] Original error stack trace: Template render error: (unknown path) [11ty] Error: filter not found: md [11ty] at Object._prettifyError (/Users/mia/Sites/mia/node_modules/nunjucks/src/lib.js:36:11) [11ty] at /Users/mia/Sites/mia/node_modules/nunjucks/src/environment.js:563:19 [11ty] at Template.root [as rootRenderFunc] (eval at _compile (/Users/mia/Sites/mia/node_modules/nunjucks/src/environment.js:633:18),In some cases, if the server was already running, I could get the plain-webC syntax to work - but still throw errors. In the terminal I would see the same error as above, but the output would be transformed. That was especially noticeable with
slugify()
.I also had issues with shortcodes, I assume related to #16