Answer the question
In order to leave comments, you need to log in
How to connect js and new block through own module in Drupal8?
Hello. Please help me figure out how to add js and blocks through my own block. The module itself is activated in the Drupal settings. Here is what is in the LotteryList folder: LotteryList.module
file:
<?php
/**
* @file
* Code for the Chad module.
*/
?>
name: LotteryList Block
description: A simple module to demonstrate Block.
core: 8.x
package: Custom
dependencies:
- node
- block
type: module
global-styling:
version: 1.x
js:
js/custom.js: {}
dependencies:
- core/jquery
- core/jquery.once
<?php
/**
* @file
* Contains \Drupal\LotteryList\Plugin\Block\LotteryListBlock.
*/
namespace Drupal\LotteryList\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'LotteryList' block.
*
* @Block(
* id = "lotterylist_block",
* admin_label = @Translation("LotteryList block"),
* category = @Translation("Custom LotteryList block")
* )
*/
class LotteryListBlock extends BlockBase {
/**
* { @inheritdoc}
*/
public function build() {
return array(
'#type' => 'markup',
'
);
}
}
(function ($) {
Drupal.behaviors.myModuleBehavior = {
attach: function (context, settings) {
$(context).find('.click-me').once('myCustomBehavior').click(function () {
alert('Hello, World!');
});
}
};
})(jQuery);
Answer the question
In order to leave comments, you need to log in
1. Drop the folder with the module in site_folder/modules/custom (if "custom" is not present, create it)
2. Enable the module in the admin panel!
3. Profit!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question