Call javascript functions in another file from EJS templates in Harp.js

Trying to create a site using Harp.js here. I am using ejs templates and want to save some useful javascript functions in a central file. How should I do it? I tried to use

<% include _render_util.js %>

But this does not work (it seems that the js file is not parsed).

Any ideas? Thank!

+4
source share
1 answer

Although there are ways to make this work (sometimes), this is not what was built into Harp.js. This often takes time to debug and unforeseen problems.

Here is a quick experiment that I did that worked (I did not test it):

helpers.ejs

say_hello, Hello, {name}.

<%
say_hello = function (name) {
  return 'Hello, ' + name;
}
%>

index.ejs

I include helpers.ejs (, ) , . <h1>Hello, beautiful</h1>.

<% include helpers.ejs %>
<h1><%= say_hello("beautiful") %></h1>

: https://gist.github.com/jorgepedret/816c2b3985ad12cef022

GitHub , https://github.com/sintaxi/harp/issues/272

, . , .

+4

Source: https://habr.com/ru/post/1533844/


All Articles