Use vanilla js (browser) content in ejs
AngeloCore opened this issue · 1 comments
AngeloCore commented
For example:
<% let test = %> getSomething();
<h1><%= test %></h1> //SOMETHING
<script>
function getSomething() {
let smh = 'SOMETHING';
return smh
}
</script>
mde commented
This will actually work, if your function getSomething
is defined in the global context (and before you attempt to execute), and you put the function reference inside the JS block: <% let test = getSomething(); %>
.
The key here is understanding that all EJS does is build a string of executable JavaScript that it then runs in the global context, when you render the template. That's it.