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

dynamic attributes not working when using webc:keep #66

Closed
niklasgrewe opened this issue Mar 27, 2023 · 6 comments
Closed

dynamic attributes not working when using webc:keep #66

niklasgrewe opened this issue Mar 27, 2023 · 6 comments
Assignees
Labels
bug Something isn't working education

Comments

@niklasgrewe
Copy link

niklasgrewe commented Mar 27, 2023

Dynamic variables are not resolved when using webc:keep

This works ✅

<!-- layouts/base.webc -->

<link rel="stylesheet" href="assets/css/index.css">

<!-- will render to -->
<link rel="stylesheet" href="assets/css/index.css">

But this doesn't work 🚫

<!-- layouts/base.webc -->

<link webc:if="css" webc:keep rel="stylesheet" :href="css">

<!-- will render to -->
<link rel="stylesheet" href="function (...args) {
   benchmark.before();
   let ret = callback.call(this, ...args);
   benchmark.after();
   return ret;
}">
@niklasgrewe niklasgrewe changed the title Resolve dynamic attributes in js template dynamic attributes not working when using webc:keep Mar 27, 2023
@zachleat zachleat added the bug Something isn't working label Mar 30, 2023
@zachleat zachleat self-assigned this Mar 30, 2023
@zachleat
Copy link
Member

Can you provide how base.webc is being used? Just trying to glean how you’re setting css.

css is a provided WebC helper from https://github.com/11ty/eleventy-plugin-bundle (and I agree this is confusing)

@niklasgrewe
Copy link
Author

niklasgrewe commented Mar 30, 2023

my base.webc looks like this:

<!doctype html>
<html lang="en">
   <head>
        <meta charset="utf-8">
	<title @text="title"></title>
	<style @raw="getBundle('css')" webc:keep></style>
   </head>
   <body @raw="content"></body>
</html>

@zachleat
Copy link
Member

Ah, then is your original comment mislabeled? I would like to know what css is (or what you expect it to be) in this example:

<!-- layouts/base.webc -->

<link webc:if="css" webc:keep rel="stylesheet" :href="css">

<!-- will render to -->
<link rel="stylesheet" href="function (...args) {
   benchmark.before();
   let ret = callback.call(this, ...args);
   benchmark.after();
   return ret;
}">

@niklasgrewe
Copy link
Author

sorry i forgot something... my base.webc looks like this:

<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title @text="title"></title>
      <link webc:keep rel="stylesheet" :href="`assets/css/${this.css}`" />
      <style @raw="getBundle('css')" webc:keep></style>
   </head>
   <body @raw="content"></body>
</html>

and inside my home.webc i set the css inside my frontmatter like this:

---
layout: layouts/base.webc
css: home.css
---

but this:

<link webc:keep rel="stylesheet" :href="`assets/css/${this.css}`" />

will render to:

<link rel="stylesheet" href="function (...args) {
   benchmark.before();
   let ret = callback.call(this, ...args);
   benchmark.after();
   return ret;
}">

@zachleat
Copy link
Member

Perfect, that’s what I needed, thank you.

@zachleat
Copy link
Member

Fixed by 731604f

@zachleat zachleat transferred this issue from 11ty/webc Mar 31, 2023
@zachleat zachleat added this to the Eleventy WebC v0.11.0 milestone Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working education
Projects
None yet
Development

No branches or pull requests

2 participants