ファイル内の変数"name"
にアクセスする方法res.render
を使用していますか?express.js/node.jsのres.render()を使用してhtmlファイルとともにデータを送信してください
app.get("/", function(req, res){
res.render('index.html',{name: "xyz"});
});
後、私はNode.jsの中で同じ達成したい、CodeIgniterの例です:
$data["name"] = "xyz"
$this->load->view("index", $data);
CodeIgniterの中で仕事をしながら、私はindex.html
で$name
を使用して"name"
にアクセスすることができます。 node.jsを使用して変数にアクセスするにはindex.html
?
テンプレートエンジンを使用する必要があります。 https://expressjs.com/en/guide/using-template-engines.htmlをチェックしてください。 – Hosar
Thanks Hosar。それはまさに私が探していたものです。 –