-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Precompiling templates? #268
Comments
@henderea thanks for the question! I think this should be possible using |
Well, at the very least, there's no named export named To be clear, it all works fine with 2.2.0 and earlier. I'm just looking for a 3.x equivalent so I can upgrade. |
@henderea methods in Eta v3 moved to be part of an Eta class. Try something like this. var { Eta } = require('eta')
const eta = new Eta()
const template = 'hello <%= it.name %>!'
const compiled = eta.compile(template)
// these two are equivalent:
eta.renderString(template, {name: 'Ben'})
// and
compiled.call(eta, {name: "Ben"})
// Now if you want to get the function as a string
compiled.toString() Basically you'll need to call |
Is it actually necessary to set the |
@henderea it is necessary to set |
@henderea FWIW, here is how I would add Eta SSR support to my framework: import { Eta } from "eta";
import { File } from "rcompat/fs";
const eta = new Eta();
const template = `<% if (it.user) { %>
<h2><%= it.user.name %></h2>
<% } %>`;
await File.write("./compiled.js", `
import { Eta } from "eta";
const eta = new Eta();
${eta.compile(template).toString()}
export default (props, options) => anonymous.call(eta, props, options);
`);
import("./compiled.js").then(imported => {
// -> <h2>foo</h2>
console.log(imported.default({ user: { name: "foo" }}));
}) |
Is your feature request related to a problem? Please describe.
Version 3.x seems to have dropped support for the
compile
function, which is preventing me from using it to precompile templates for use in frontend code.Describe the solution you'd like
I would like a way to take a filename and compile it into a function, which I could then call
toString()
on to get something I can put in a file. This is what I have in 2.x (used in a gulp command; note that I haveimport { compile as etaCompile } from 'eta';
at the top of my gulpfile):The text was updated successfully, but these errors were encountered: