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

Access page level data in WebC #30

Closed
cfjedimaster opened this issue Nov 21, 2022 · 2 comments
Closed

Access page level data in WebC #30

cfjedimaster opened this issue Nov 21, 2022 · 2 comments

Comments

@cfjedimaster
Copy link

Consider the following where I define a page level variable in EJS -

<template webc:type="11ty" 11ty:type="ejs">
<%
name = "ray";
%>

</template>

Should I be able to access this in a webc file? I tried this:

<template webc:type="11ty" 11ty:type="ejs">
<%
name = "ray";
%>

</template>

<p>
I'm a cat.
</p>
<p @text="name"></p>
<p @html="name"></p>
<p :html="name"></p>
<p :title="name">title</p>

<hr>

And nothing seemed to work, but it could be that name is scoped to the template block and not used again. FYI, I realize I could just output from my EJS block, but was curious if I could use EJS to do computation type stuff, and 'regular' webc code output for the rest of the template.

As an aside (and if this should be a second issue, let me know). In the same file, I tried this on top:

---
othername: camden
---

and the front matter wasn't parsed at all.

@zachleat
Copy link
Member

zachleat commented Feb 22, 2023

Fwiw, a few things here:

  1. front matter isn’t supported by components in your components folder, it’s only on WebC input templates.
  2. webc:type="11ty" doesn’t export any data or variables—it’s merely to render template syntax. You can define variables in there for use in the same webc:type="11ty" template node, but those are locally scoped.
  3. You might be happy to see <script webc:setup> Expose JS defined in <script> tags to component's template webc#109 (coming in WebC 0.9.0, releasing soon) which will export data to your component and Set frontmatter from within component's <script> tag #45 which unlocks javascript in front matter.

@zachleat
Copy link
Member

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and we will reopen the issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants