0

I have a problem, I did not find any solution for this. This code is not working . Inside the callback function. can you please solve my problem.

exports.eejsBlock_body = function (hook_name, args, cb) {
  customUtils.getOneValueSql(getQuery).then(function (returnData) {     
    args.content = args.content + eejs.require("ep_top_menu/templates/index.ejs", {"padname":returnData}, module);
    return cb();
    });
 };
Abhi
  • 4,123
  • 6
  • 45
  • 77
Sushil Kumar
  • 15
  • 1
  • 5

2 Answers2

0
exports.eejsBlock_body = function (hook_name, args, cb) {
  customUtils.getOneValueSql(getQuery).then(function (returnData) {     
    args.content = args.content + eejs.require("ep_top_menu/templates/index.ejs", {"padname":returnData}, module);
      return cb(null, args.content);
    });
 };

Then use :

eejsBlock_body(paramHook, paramArgs, function(err, content){
   if(err){
     console.log(err);
   } else {
     console.log(content)
   }
 });
Sigma
  • 532
  • 3
  • 8
  • Hi, I do not want to console content, I want pass content to file as a parameter. – Sushil Kumar Jul 12 '17 at 03:51
  • So you can use : if(err){ return callback(err); } else { return callback (null, content) } – Sigma Jul 12 '17 at 07:58
  • I have used same : exports.eejsBlock_body = function (hook_name, args, cb) { customUtils.getOneValueSql(getQuery).then(function (returnData) { args.content = args.content + eejs.require("ep_top_menu/templates/index.ejs", {"padname":returnData}, module); return cb(null, args.content); }); }; But not wroking – Sushil Kumar Jul 12 '17 at 08:44
  • Did you try to console.log the data just to be sure that it's not empty? Can you paste the function that use the callback of eejsBlock_body? – Sigma Jul 12 '17 at 10:00
0

It looks like eejsBlock_body does not work with async changes to args.content. Do you need that query to run on the hook? Are you running the query just to get the pad name/id?

If that's the case, you could just put a placeholder (e.g.: <span id='padId'/>) on your index.ejs, and use the hook postAceInit to insert pad name into it:

exports.postAceInit = function(type, context) {
  $('#padId').text(clientVars.padId);
}
Luiza Pagliari
  • 159
  • 1
  • 3