Create custom block programmatically

how to create a custom block in Drupal 10

https://www.youtube.com/watch?v=1x7ntRl3a74


How to create custom block programmatically in Drupal 9?

https://www.youtube.com/watch?v=49psk1jLpYE


How to embed inline javascript in Drupal, anywhere on any page

https://rikdeboer.medium.com/how-to-dynamically-embed-javascript-in-drupal-anywhere-on-any-page-3f9cd7e64d0c


class MyJavascriptBlock extends BlockBase {  public function build() {
$js = \Drupal::config('mymodule.settings')->get('js_file_url')
$tag = '<script type="text/javascript" src="'.$js.'"></script>'; return [
'#markup' => $tag,
'#allowed_tags' => ['script'],
];
}
}

留言

此網誌的熱門文章

Install Drupal 10 with composer in XAMPP htdocs OR PHP Command

fix drupal 11 install error

[custom block module]Correcting Heredoc Syntax and Attaching JS