If I understand correctly, the issue you're running into is that the variables
policy is not being run before your index page is displayed, so the mensaje
variable is not available in the view. The easiest way around this is to use a controller to display the view, instead of routing to the view directly. So, in /config/routes.js
, instead of:
'/': {view: 'homepage'}
or whatever you have, do:
'/': 'HomeController.index'
and in /api/controllers/HomeController.js
:
index: function (req, res) {
res.view('homepage.ejs');
}
Change the controller and view names to suit your project. The point is that by using a controller action to display the view, you can ensure that the policy will run before the view is displayed.