1

I have a variable in my app.js and I want to print it in my HTML page without erease the other text of the page.

Example :

var test = 'hello';

Here I just want to print hello in my index.ejs page.

5
  • You need to send down and object containing the value {test: "hello"} and then inside the view you can do {{test}} and it'll print the value Commented Feb 1, 2017 at 13:48
  • How can i ''send down an object containing the value {test: "hello"}'' Commented Feb 1, 2017 at 13:49
  • If you can provide the code you have so far, we'll be able to provide a bit more help. If you're using Node.js with Express, then you can use; res.render("index", {text: "hello"}); Commented Feb 1, 2017 at 13:52
  • .I have a page app.js with a var and a page index.ejs with HTML code. I just want to print the var. Commented Feb 1, 2017 at 13:54
  • Ok I will try this. Commented Feb 1, 2017 at 13:55

1 Answer 1

2

var test = 'hello'; is a variable that you declared it in the app.js. You can print it through the console as console.log(test) If you want to print it in your html template, it has to be an object. {test: 'hello'} can be printed as {{test}} in your ejs html template.Take a look at the documentation of ejs template engine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.