views:

31

answers:

1

Hi,

I am using the micro template (Micro Template) in my project. Below is the sample

<script type="text/html" id="user_tmpl">
  <% for ( var i = 0; i < users.length; i++ ) { %>
    <li><a href="<%=users[i].url%>"><%=users[i].name%></a></li>
  <% } %>
</script>

Is it possible to call a javascript function say a simple function like this:

function SubstringText(input,length) {
    return input.substring(1, length);
} 

on users[i].name property ?

+1  A: 

You can call it directly in the script, for example:

<script type="text/html" id="user_tmpl">
  <% for ( var i = 0; i < users.length; i++ ) { %>
    <li><a href="<%=users[i].url%>"><%=SubstringText(users[i].name, 5)%></a></li>
  <% } %>
</script>

I'm not sure what length you want here, just replace 5 with whatever that is in the example above.

Nick Craver
Awesome! Thanks :)
Rocky Singh