Move javascript out of block tpl file with drupal_add_js

Created on 29 December 2013, almost 11 years ago
Updated 9 June 2023, over 1 year ago

I moved all of my js files to the bottom of the page for front-end performance improvement. After I did that, ads were no longer showing due to following js error:

ReferenceError: Can't find variable: _simpelads_load

This is because now simpleads.js is loaded after the function above called from templates/simpleads_block.tpl.php.

SOLUTION

(for me)

Replace following in simpleads_block.tpl.php:

<script type="text/javascript">
  _simpelads_load('.simpleads-<?php print $tid; ?><?php if ($prefix) : ?>-<?php print $prefix; ?><?php endif; ?>', <?php print $tid; ?>, <?php print check_plain($ads_limit); ?>);
</script>

With:

<?php
   drupal_add_js("_simpelads_load('.simpleads-" . $tid . (($prefix) ? "-" . $prefix : "") . "', " . $tid . ", " . check_plain($ads_limit) . ");", array('type' => 'inline', 'group' => JS_THEME));
?>

*** Why is it _simpelads_load instead of _simpleads_load?

πŸ“Œ Task
Status

Closed: won't fix

Version

1.9

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States moehac

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024