Search code examples
javascriptnode.jsexpressincludeejs

node.js ejs include partials, and in the main, can't find the variable defined in the partial file


this is my code to be included in the main ejs file.

<%

const IDP_URL = "http://idp.com:8082";
const SP_ID = "testing";
const SP_SECRET = "XRRpYIoMtaJC8hFLfUN7Bw==";
const TOKEN_VERIFY_FAIL_URL ="/exsignon/sso/token_verify_fail.ejs";
const LOGINUSER_REDIRECT_URL = "/exsignon/sso/sso_loginuser.jsp";
const ANONYMOUS_REDIRECT_URL = "/exsignon/sample/main.jsp";

%>

and in my main ejs file I'm trying to call sp_ID, and won't recognize and throws an error that sp_id is not defined, I've used many types of includes(<% include filename %>, <%- include filename %>, <%- include (filename) %>) and etc

any ideas would be appreciated


Solution

  • You have to wrap all your javascript code in <% %> tags

    <% const IDP_URL = "http://idp.com:8082"; %>
    <% const SP_ID = "testing"; %>
    <% const SP_SECRET = "XRRpYIoMtaJC8hFLfUN7Bw=="; %>
    <% const TOKEN_VERIFY_FAIL_URL ="/exsignon/sso/token_verify_fail.ejs"; %>
    <% const LOGINUSER_REDIRECT_URL = "/exsignon/sso/sso_loginuser.jsp"; %>
    <% const ANONYMOUS_REDIRECT_URL = "/exsignon/sample/main.jsp"; %>