You can call drupal_add_js()
and drupal_add_css()
in a hook_preprocess_block__module()
or hook_preprocess_block__module__delta()
function (replacing 'hook', 'module' and 'delta' with specific values) that you define in your module alongside your hook_block_view()
function, or in your theme's 'template.php' file.
How to concretely display any kind of content within a drupal module
-
30-06-2022 - |
Вопрос
this will be my first question on the site, I hope I'll be clear!
So I'm working on adapting a regular php/html/js website to a drupal site. There are some specific things a can't do with the available modules, so a need to create some. I've been wandering a lot on the web, watch and read some tutorials but I dont get exactly how to display simple html/js/php with a block module for instance.
For example, I want to display this in a block module :
`<script type="text/javascript" src="jquery-min.js"></script>
<div class="myDiv"></div>
<script>
$(".maparea").append('<p class='myText'>Hello there!</p>');
</script>`
On the other hand I have my block_view function:
`function my_module_block_view($delta = '') {
$block = array();
$block['subject'] = 'my Module title';
$block['content'] = 'some content';
return $block;
}`
If i replace that 'some content' with my raw code, well first I don't think it is the best way, a overall it doesn't work so well. Besides, I would like to use the drupal API to insert js (drupal_add_js), but how?
`block['content'] .= drupal_add_js(drupal_get_path('module', 'my_module').'/myScript.js');`
Finally, I found some information about theme system, and templates. So it seems I have to implement my_module_template.tpl.php, and implement hook_theme in my_module.module.
It's pretty blurry, so I really need some help to understand the basics.
Thanks in advance!
Решение