-1

I have this Drupal Behaviors Javascript code:

Drupal.behaviors.myid_templates = {
    attach: function(context, settings){
        function local_function(){
            alert('local_function');
        }
    }
}

function global_function(){
    //I want to call local_function here. Is that possible?
    local_function();
}

I was wondering I could do something like Drupal.behaviors.myid_templates.local_function() to access local functions from global functions? Any idea? Thanks.

  • This is a valid Question, why the downvote ?? – Sanjok Gurung Aug 11 at 19:00
4

You would need to add it to Drupal.behaviors.myid_templates and not inside of your attach function.

Drupal.behaviors.myid_templates = {
  attach: function(context, settings){
    // Code to run on DOM ready, each AJAX request finish.
  },
  local_function: function (){
    alert('local_function');
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy