3

How can I access the data in a template?

Below is the code from file server.js (main Node.js module):

var engine = require('express-ejs-layouts');
app.get('/', router);
app.engine('ejs', engine);
app.set('view engine', 'ejs');
app.engine('php', phpnode);
app.set('view engine', 'php');

File routes.js

// Initialize views
router.get('/', function(req, res){
   res.render('index', {data : 'jobDataVal'});
})

File index.php (template file)

<!DOCTYPE html>
<html>
   <head>
      <title></title>
      <?php include_once('header_scripts.php'); ?>
   </head>
   <body>
     <?php echo $data; ?>
     <%= data %>
     <?php include_once('footer_scripts.php');?>
   </body>
</html>

I am trying to access a data variable from routes in the template, but the value is not accessible.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

0
<?= $data ?>

That is using PHP syntax.

Adude
  • 62
  • 7