{"id":753,"date":"2022-08-30T15:06:36","date_gmt":"2022-08-30T15:06:36","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/when-i-pass-res-render-object-then-in-ejs-file-it-is-undefined-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:06:36","modified_gmt":"2022-08-30T15:06:36","slug":"when-i-pass-res-render-object-then-in-ejs-file-it-is-undefined-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/when-i-pass-res-render-object-then-in-ejs-file-it-is-undefined-collection-of-common-programming-errors\/","title":{"rendered":"When I pass res.render object then in .ejs file it is undefined-Collection of common programming errors"},"content":{"rendered":"<p>I want to show values of post object in my profilearea.ejs file.But when it renders to profilearea.ejs then it gives an error that &#8220;post is not defined&#8221;.<\/p>\n<p>Here is the code in node.js<\/p>\n<pre><code>PersonalInfo.findOne({username:req.body.name}, function(err,post){\n    if(err || !post)\n    {\n        console.log(\"find is not done\");\n    }\n\n    else\n        res.render('profilearea.ejs', {post:post});\n\n  }\n\n})\n<\/code><\/pre>\n<p>This is the code in profilearea.ejs file<\/p>\n<pre><code>\n       <\/code><\/pre>\n<h2><code>INFORMATION<\/code><\/h2>\n<pre>\n       \n\n        <br \/>  \n       \n      \n<\/pre>\n<ol>\n<li>\n<p><code>I think part of the issue may be in not stringifying the object prior to rendering.<\/code><\/p>\n<p><code>Try:<\/code><\/p>\n<pre><code><code>  else {\n  var jpost = JSON.stringify(post);\n  res.render('profilearea.ejs', {post:jpost});\n  }\n<\/code><\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:38:34. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I want to show values of post object in my profilearea.ejs file.But when it renders to profilearea.ejs then it gives an error that &#8220;post is not defined&#8221;. Here is the code in node.js PersonalInfo.findOne({username:req.body.name}, function(err,post){ if(err || !post) { console.log(&#8220;find is not done&#8221;); } else res.render(&#8216;profilearea.ejs&#8217;, {post:post}); } }) This is the code in profilearea.ejs [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-753","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=753"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/753\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}