You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
pautasso
changed the title
Function do not return embedded HTML
Functions do not return embedded HTML
Aug 31, 2023
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:
<%functionf() {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.
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.
The text was updated successfully, but these errors were encountered: