eta-dev / eta

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript

Home Page:https://eta.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to remove '=' from left delimiter?

sanketdhoble opened this issue · comments

Query-1:
I changed delimter to {{ }} with

eta.configure({
    tags: ['{{', '}}']
})

I still have to print variables using my age is {{= it.age}}. Is it possible to remove this = sign from delimter syntax?

Query-2:
Is it possible to remove 'it' for variable and directly print it like this my age is {{age}} instead?

Query-3:
eta throws error if age is not present in my nested source object when trying to access, {{it.data.age.test}}
Is there a way to overcome this?

  1. Pass in option parse: {exec: "$", interpolate: "", raw: "~"}. Note: to run code, you'll have to prefix it with "$": {{$ if(x) }}
  2. Yes, pass in option useWith: true
  3. Use optional chaining: {{it.data?.age?.test}}

@nebrelbug
Thanks for clarifying point 1 & 2.

Regarding point 3. Optional chaining doesn't work with older node versions ( node 13 and below ). Plus I have to add ? everytime in my template.
I was wondering if there is way to do this via eta only similar to other templating tools like liquidJs, twigJs where by default it prints empty string if value is not accessible or undefined.

@sanketdhoble sure, you can define an auto-filter function to do a try-catch around interpolations.

https://eta.js.org/docs/api#auto-filtering-data