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.34k stars 60 forks source link

Add an Output function (like EJS's `outputFunctionName`) #284

Open paul-norman opened 2 months ago

paul-norman commented 2 months ago

Is your feature request related to a problem? Please describe.

Often I'd like the ability to output code from a function rather than having to close / open the tags to do this. In EJS this is possible via the outputFunctionName option.

In short, I'd like to be able to write something like:

<% if (condition) { print(`string ${variable} string`) } %>

rather than:

<% if (condition) { %>string <%= variable %> string<% } %>
// or, more likely:
<% if (condition) { -%> string <%= variable %> string <%- } %>

Describe the solution you'd like

Either a function, or the documentation to make a function, that will allow me to output directly without opening and closing tags excessively. My IDE (WebStorm) doesn't support ETA with customised tags at all (I like <? / ?>), and provides terrible EJS support too, so I'm basically looking at monocoloured code files and find the first form far more familiar to me (and easier to type).

Describe alternatives you've considered

Opening and closing tags a lot! This is very annoying when refactoring EJS code that could take advantage of the outputFunctionName

nebrelbug commented 2 months ago

@paul-norman I like this idea. If anyone wants to contribute a PR, let's call the output function output by default.