I have created custom module with drupal 8 after successfully installation on my module run properly with java script but after its not working till now , i have done multiple changes in my module controller file but module has not run .

my controller file code is here :


 * @file
 * Controller for generating JSON response.

namespace Drupal\ipew\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Database\Database;

 * Controller for d3 ipew.
class ipewController extends ControllerBase {
   * Display the markup.
   * @return array

   public function content() {

      return [
      '#title' => 'Hello World',
      '#markup' => 'Welcome to this World',


*.info.yml file code is here :

name: ipew
type: module
description: Attack map
core: 8.x
package: Custom

*.liabraries.yml code is here :

  version: 1.x
    js/d3.v3.min.js: {}
    js/ipew.js: {}
    js/d3.geo.projection.v0.min.js: {}
    js/topojson.v1.min.js: {}
    js/datamaps.world.min.js: {}
    js/jquery-2.1.1.min.js: {}
    js/jquery.simplemodal-1.4.4.js: {}
    - core/drupal
    - core/jquery
    - core/drupalSettings

*.routing.yml is here :

  path: '/ipew'
    _controller: '\Drupal\ipew\Controller\ipewController::content'
    _title_callback: '\Drupal\ipew\Controller\ipewController::getTitle'
    _permission: 'access content'

*.html.twig file is here :

{# ipew/templates/ipew.html.twig #}
<svg width="960" height="600"></svg>

This module only show hello world in output .


You need to attach your library:

return [
  '#title' => 'Hello World',
  '#markup' => 'Welcome to this World',
  '#attached' => [
    // Add the ipew library from the ipew module
    // in the format [MODULE]/[LIBRARY].
    'library' => 'ipew/ipew',

As japan told you, you need to attach the library.

You need also to configure your ipew.libraries.yml

  version: 1
    js/your-file.min.js: {minified: true}
    - core/jquery

And in your js file :

(function ($, Drupal) {
    Drupal.behaviors.ipew = {
        attach: function (context, settings) {
             // your js code

})(jQuery, Drupal);

The advantage of Behaviors over document.ready() is that they are automatically re-applied to any content loaded through AJAX : Better understanding of Drupal behaviors

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.