Open pautasso opened 1 year ago
Yeah, the function just appends at call time. This can be demonstrated by the fact that <% f() %>
(scriptlet tag, not an output tag) will still output <p>from function</p>
. If you want your function to actually return something, you'd write it like this:
<% function f() {
return '<p>from function</p>'
} %>
Of course, you wouldn't be able to use EJS inside the function. Defining functions in EJS is generally inconvenient; you probably want to make your function an included partial instead.
(...leading to many small partial include files, which could have been functions instead)
Thanks for the explanation, maybe the documentation could be clarified to say something like:
One can use functions with ejs, but those functions do not return the embedded HTML/JS content.
view.ejs file:
include.ejs file:
The output will be:
As opposed to:
Functions emit the embedded html by appending it to the output of the view in which they are declared. If they are called from another view, they will not use the "correct" output buffer of the .ejs in which they are called from but the one in which they have been declared.