Although there are ways of making this work (sometimes), it's not something that was deliveratly built into Harp.js. Forcing this behaviour often takes time to debug and causes unexpected issues.
Here is a quick experiment I made that works (I didn't throughly test it):
helpers.ejs
I created a say_hello
function that takes a name and outputs the string Hello, {name}
.
<%
say_hello = function (name) {
return 'Hello, ' + name;
}
%>
index.ejs
I include helpers.ejs
(the file mentioned above) in the first line and then use the function in the second line. That outputs <h1>Hello, beautiful</h1>
.
<% include helpers.ejs %>
<h1><%= say_hello("beautiful") %></h1>
Example gist: https://gist.github.com/jorgepedret/816c2b3985ad12cef022
There's an open issue on GitHub discussing this issue https://github.com/sintaxi/harp/issues/272
This example is more of a hack than a recommended solution. I've seen cases where it breaks in unexpected ways.