insert script tag with data using ejs (ejs-locals) on express.js

I'm using ejs-locals for express 3.x (https://github.com/RandomEtc/ejs-locals)

How would I insert a script tag from a template with dynamic data?

In my layout.ejs I have

<%- block.scripts %>

In my page template login.ejs I want to replace it with some dynamic data:

<% block('scripts', "<script> var app = window.app || {}; app.err = <%- JSON.stringify(err) %>, app.q = <%- JSON.stringify(q) %>; </script>") -%>

I get an error:

500 SyntaxError: Unexpected token % -- i'm assuming because I can't do <%= JSON.stringigy(err) %> here.

I solved the problem by moving the script insertion to layout.ejs since it's always the same.

    <% include script %>
  </body>

Otherwise, you have to terminate the string:

//this works but is rather cumbersome to do on every page template.
  <% block('script', '<script>' +
    'app.req.err = '+ JSON.stringify(err) +";\n" +
    'app.req.q = '+ JSON.stringify(q) +";\n" +
  '</script>') %>