Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Feb 24 17:52
    js2me synchronize #94
  • Feb 24 07:45
    js2me synchronize #94
  • Feb 24 01:43
    js2me opened #94
  • Feb 17 09:24
    niraj-khatiwada commented #92
  • Feb 17 09:20
    shadowtime2000 closed #92
  • Feb 17 09:20
    shadowtime2000 commented #92
  • Feb 17 09:19
    niraj-khatiwada commented #92
  • Feb 17 09:13
    shadowtime2000 commented #92
  • Feb 17 09:12
    niraj-khatiwada commented #92
  • Feb 17 09:11
    niraj-khatiwada commented #92
  • Feb 17 09:06
    shadowtime2000 commented #92
  • Feb 17 09:01
    niraj-khatiwada commented #92
  • Feb 17 08:50
    shadowtime2000 commented #92
  • Feb 17 08:48
    niraj-khatiwada commented #92
  • Feb 17 08:45
    shadowtime2000 commented #92
  • Feb 17 08:44
    shadowtime2000 closed #93
  • Feb 17 08:44
    shadowtime2000 commented #93
  • Feb 17 08:39
    niraj-khatiwada reopened #92
  • Feb 17 08:39
    niraj-khatiwada closed #92
  • Feb 17 08:39
    niraj-khatiwada commented #92
orellabac
@orellabac_twitter
very much like doing <%=value%>
I just wanted to see if there is a way to do something similar

for example a typical approach in ASP is:
function doHeader() {
Response.Write('<h1> header </h1>');
}

and then in your page you can do:
<%
doHeader();
%>
So I just wondered how to do that.
The imports is that for example i am using the node npm for mssql and I do not want to have to import it everywhere. So maybe I can inject common used stuff with a plugin ?

shadowtime2000
@shadowtime2000
@orellabac_twitter For the response.write thing I am understanding you are talking about partials which can be reused. Injecting stuff with a plugin is currently not a feature, you can use a processFnString hook to inject some stuff right before it, though that doesn't seem that clean or anything. I opened an issue about that in #62
Emmanuel Segun-Lean
@LeanKhan
@shadowtime2000 using useWith solved my problem. Thanks
happy holidays to all :smile_cat:
shadowtime2000
@shadowtime2000
@LeanKhan Oh sorry, I didn't notice your message there. Glad you were able to find a solution, happy holidays to you too :)
Rubin Bhandari
@rubiin
how can i push some data inside script
i need to set a variable inside templates script tag
Emmanuel Segun-Lean
@LeanKhan

hi @rubiin you can try in your template

<script data="<%= it.data %>">
    const data = document.getCurrentScript.getAttribute('data');

    console.log(data);
</script>

If you pass an object or array for example, you would have to stringify it first, then parse it in your javascript. You get?

Rubin Bhandari
@rubiin
let me try it, i think i get it. mine was an array of numbers so let me try
Rubin Bhandari
@rubiin
        var options = {
     series: JSON.parse([40,40,40,40]),
          colors: [
      '#29A5A5',
      '#64CD82',
      '#F3E45C',
      '#FF0000'
    ],
    labels: ['Invited', 'Requested', 'Not-approved', 'Not-invited'],
    chart: {
      width: 210,
      type: 'donut'
    },
    dataLabels: {
      enabled: true,
    },
    legend: {
      show: false
    }
  };
  var charts = new ApexCharts(document.querySelector("#chart"), options);
  charts.render();
</script>
i get something like this, however the piechart is not showing
Emmanuel Segun-Lean
@LeanKhan
@rubiin well Iha
Emmanuel Segun-Lean
@LeanKhan
Well I haven't used ApexCharts before. But you can only parse strings with JSON.parse() not an array. To convert the Array to string use JSON.stringify() then parse it back to a Javascript Array that you can use.
@rubiin I don't know why the chart is not showing. It probably doesn't have to do with Eta tho
shadowtime2000
@shadowtime2000
Yeah it most likely has something to do with how you render the data in the JS
Rubin Bhandari
@rubiin
i figured it out
shadowtime2000
@shadowtime2000
cool
Emmanuel Segun-Lean
@LeanKhan
<%~ E.includeFile("cart-component.vue") %>
I still wonder why this works ^
<cart-component :items="<%= items %>"></cart-component>
shadowtime2000
@shadowtime2000
I actually saw a stackoverflow for that but for EJS
the reason is that any file that is used will be used as if it was an Eta file
so basically it will just copy and paste it if there are no delimiters @LeanKhan
Orellabac
@orellabac
Hi. I few weeks ago I discovered eta I was very happy. It reminded my of ASPClassic and I decided to the a toy project where I could try it out. I had to create a plugin (probably not in the best way) and was able to reproduce most if this features. So if anybody else is interested please visit: https://github.com/orellabac/asp-classic-to-nodejs
Davorin Šego
@dsego
Hi folks,
What do you think about having a function/directive that does parallel async includes?
Like the following example, but without the boilerplate of doing Promise.all.
<%
const [AsyncComponent1, AsyncComponent2] = await Promise.all([
  includeFile('AsyncComponent.eta', { delay: 200 }),
  includeFile('AsyncComponent.eta', { delay: 300 })
])
%>
<h1>This should take ~300ms </h1>
<%~ AsyncComponent1 %>
<%~ AsyncComponent2 %>
I would like to just do this instead:
<h1>This should take ~300ms </h1>
<%~ defer('AsyncComponent.eta', { delay: 200 }) %>
<%~ defer( 'AsyncComponent.eta', { delay: 300 }) %>
I've been trying to make a plugin that does this, but can't make it work yet.
Damian
@damiantoczek
Hello, I come from EJS and I have a layout that has other layouts inside, how can I do this with Eta? For example my layout is called layout.eta, then i have a page called cpu-list.eta and the cpu-list has includes. But I don't know how to add the cpu-list into the layout. Because in EJS it's res.render('cpu-list', {layout: './layout.ejs'});
Damian
@damiantoczek
Ok I got it i need to use and add body: await eta.renderFile().
shadowtime2000
@shadowtime2000
@dsego What have you gotten so far? I think it should pretty simple, when you process the template you get everything defer usage and then add the statement at the top and replace the defer statements.
5 replies

Ok I got it i need to use and add body: await eta.renderFile().

@damiantoczek I am a little confused by what you mean by this, but you should check out the docs page on layouts

Davorin Šego
@dsego
What's the meaning behind t values being i, e and r ?
shadowtime2000
@shadowtime2000
@dsego i means simple interpolated values with <%= e means <% and r means <%~, I actually don't know the reasoning behind shortened names like this
Davorin Šego
@dsego
ah so e is probably eval and r could be raw.
Thanks!
shadowtime2000
@shadowtime2000
np
shadowtime2000
@shadowtime2000
Poll: How would you feel about more content being added to the Blog part of the docs site?
I noticed it doesn't really have much but adding some good template engine related content may be worth it to drive more people to Eta
Emmanuel Segun-Lean
@LeanKhan
@shadowtime2000 i didn't even know about the blog until now. Its a single post I'm seeing introducing Eta. Yeah, it could have articles that address some commom problems devs have with Nodejs template engines. With some good SEO, more people will know about it.
shadowtime2000
@shadowtime2000
Maybe I could write a post there like "What is an Embedded JS Template Engine?"
Emmanuel Segun-Lean
@LeanKhan
@shadowtime2000 hmm, i think the title is too long haha and not approachable. But yeah its a good start
What makes it 'embedded' actually?
shadowtime2000
@shadowtime2000
@LeanKhan Embedded means instead of it's own kind of language, within delimiters it is the same language that is controlling how the template renders inside the template
shadowtime2000
@shadowtime2000
like how we have js inside the delimiters
maybe it could be different types of template engines, basically differentiates embedded and logic less
shadowtime2000
@shadowtime2000
@LeanKhan I just did a small post about embedded js template engines https://eta.js.org/blog/what-is-embedded-js-template-engine - hope it helps you understand :)
Emmanuel Segun-Lean
@LeanKhan
Okay just read it hehe. It helps thank you. Aren't there embedded template engines for other languages besides js? And the definition also applies to them. Like erb for Ruby
@shadowtime2000 also, can you show examples from other languages perhaps. Or the difference between embedded ones and those that are not embedded?