eta-dev / eta

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript
https://eta.js.org
MIT License
1.41k stars 65 forks source link

From V2 to V3 and from `includeFile` to `include` #257

Closed bacloud23 closed 1 year ago

bacloud23 commented 1 year ago

Hi, I was using includeFile fine, and along with global configuration useWith: true, I have been using:

|--index.eta
|--  includeFile('head.eta', it)

|--head.eta
|-- // variables inside `it` just work
|-- // it is well present and loaded in V3

Now includeFile bugs so I changed it to include, along with useWith: true, but variables are not being passed.

Adding it. to each variable will be painful :/ so better to find a better way

Thanks a lot ^^

bacloud23 commented 1 year ago

by the way everything suggested here does not work https://github.com/eta-dev/eta/issues/254

(passing destructed {it}, or an empty object {})

nebrelbug commented 1 year ago

@yanna92yar you should be able to do include('head.eta', it). Does that not work?

bacloud23 commented 1 year ago

No it doesnt, it was that way also before with includeFile, so I didn't change that. Every partial has the parent calling with it

nebrelbug commented 1 year ago

@yanna92yar could you give me a minimal example?

bacloud23 commented 1 year ago

This is an example: https://github.com/yanna92yar/test-eta

If you check: https://github.com/yanna92yar/test-eta/blob/main/templates/partial.eta and try to use variable without it it crashes.

Thanks a lot ^^

nebrelbug commented 1 year ago

You need to pass the config directly into the Eta() constructor. In your repo,

  engine: {
    eta: new Eta.Eta({ useWith: true })
  },
bacloud23 commented 1 year ago

Thanks a lot 🙏