0

I'm building a project on top of some existing code written by another developer. It's a JavaScript project to build a chrome extension. One of the HTML files has some code written in the following format:

<% $.each(this, function(index, value) { %>

<% var valPart = value.from_mail.split('<'); %>
<% var name = valPart[0]; %>
<% var ma_name= name; %>

And some of the HTML tags on the page contain elements like

<a class='view_name' title='<%= value.fileName %>' href='<%= getViewUrl(value.viewUrl) %>'><%= value.fileName %></a> 

getViewUrl is a function defined in the code. My main query is with the code between the <%...%>

Now, I have a fair idea that Embedded Ruby HTML files use <% ... %> for creating code elements inside the HTML file. I know for fact that Ruby isn't being used in this project or even ERB files for that matter. Any idea what this could be?

Newtt
  • 6,050
  • 13
  • 68
  • 106

2 Answers2

3

Looks like an underscore template: http://underscorejs.org/#template

almost smart
  • 115
  • 6
  • Looks like it. @Newtt, Check out [this question](http://stackoverflow.com/questions/4778881/how-to-use-underscore-js-as-a-template-engine) as well, it shows some templating similar to what you have. – Josh Beam Mar 10 '14 at 11:24
  • Makes sense. However, doesn't underscore require to be installed in the project? I couldn't find any place where Underscore.js was installed or called into my project. – Newtt Mar 10 '14 at 11:29
0

I've inherited code with that same syntax in the html pages too. I'm working on an application which uses html, javascript and java. The code that I have uses <%=....%> syntax to reference java code and is called a scriplet. Perhaps that's your case as well? Below is from the oracle documentation for scriplets.

JSP Scriptlets

A JSP scriptlet is used to contain any code fragment that is valid for the scripting language used in a page. The syntax for a scriptlet is as follows:

<%
    scripting-language-statements
%>

When the scripting language is set to java, a scriptlet is transformed into a Java programming language statement fragment and is inserted into the service method of the JSP page’s servlet. A programming language variable created within a scriptlet is accessible from anywhere within the JSP page.

In the web service version of the hello1 application, greeting.jsp contains a scriptlet to retrieve the request parameter named username and test whether it is empty. If the if statement evaluates to true, the response page is included. Because the if statement opens a block, the HTML markup would be followed by a scriptlet that closes the block.

<%
   String username = request.getParameter("username");
   if ( username != null && username.length() > 0 ) {
%>
       <%@include file="response.jsp" %> 
<%
   }
%>

Here's the link to the doc: http://docs.oracle.com/javaee/5/tutorial/doc/bnaou.html

Chuck L
  • 1,026
  • 10
  • 23