A
A
Anton Valerievich2016-12-18 10:14:07
Drupal
Anton Valerievich, 2016-12-18 10:14:07

How in Drupal 7, to all js scripts displayed in the header, specify the type of script?

Hello! Please tell me how to solve the problem. The situation is this, I work in the Drupal7 environment, and there all js scripts are output by a variable, and the scripts are connected through the name_themes.info file with the instruction scripts[] = 'myjs.js'. So, everything would be fine, but they are displayed without specifying the type of script type="text/javascript" The output looks like this But it should look like this<?php print $scripts; ?>
<script src="myjs.js"></script>

<script type="text/javascript" src="myjs.js"></script>

or
<script type="text/javascript" async src="myjs.js"></script>

If all the scripts are written manually, in the html.tpl.php file between the tags, then it will probably not be kosher in relation to the Drupal API.
Is there a solution to this problem?
Of course, you can do this by writing in the template.php file
function имяТемы_preprocess_page(&$vars) {
  if ($vars['type'] == 'my-node-type') {
    drupal_add_js(drupal_get_path('theme', 'имяТемы') . '/myjs.js');
  }
}

Then again, where to write async and you will have to create one myjs.js file and import the rest of the scripts into it, but I don’t know how scripts are imported, well, all this will have to be done, because 2 or more cannot exist in template.php the same functions.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Valeryevich, 2016-12-19
@WebThinker

In general, this is what I did.
Wrote an uncomplicated myj.js script, connected it through an info file with the theme name.

$import("/js/myjs1.js");
$import("/js/myjs2.js");
$import("/js/myjs3.js");
function $import(path){
    var  scripts = document.write("<" + "script async src=\"" + path + "\"></" + "script>");
}

And through it, I already ran the scripts I needed with the attribute I needed by importing. Works great.
I really don't know if it's kosher or not. Unsubscribe if possible, your opinion is always appreciated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question