Posts

Showing posts with the label Scope

Can A Js Script Get A Variable Written In A EJS Context/page Within The Same File

Answer : Edit : this Half considers you are using EJS on server side 1) You can pass an ejs variable value to a Javascript variable <% var test = 101; %> // variable created by ejs <script> var getTest = <%= test %>; //var test is now assigned to getTest which will only work on browsers console.log(getTest); // successfully prints 101 on browser </script> simply create an ejs variable and assign the value inside the script tag to the var getTest Ex: var getTest = <%= test %>; 2) You can't pass an javascript variable value to a ejs variable Yes, you cant: if it is on server. Why: The EJS template will be rendered on the server before the Javscript is started execution(it will start on browser), so there is no way going back to server and ask for some previous changes on the page which is already sent to the browser. Edit : this Half considers you are using EJS on Client...