0

The site is the most stock, only Drupal 7 core is installed.

included my theme, where the page.tpl and html.tpl theme files are copied from core

I created a Yandex.Maps module, this is a block where js is added.

<?php
  function yamap_block_info(): array {
    $blocks['yamap'] = [
      'info'  => 'Block Yandex.Map',
      'cache' => DRUPAL_CACHE_PER_ROLE,
    ];
    return $blocks;
  }
  
  function yamap_theme(): array {
    return [
      'main-yamap' => [
        'template' => 'yamap-block',
      ],
    ];
  }
  
  function yamap_block_view($delta = ''): array {
    if ($delta == 'yamap') {
      $module_path = drupal_get_path('module', 'yamap');
      drupal_add_js($module_path . '/src/js/yamap.js', ['scope' => 'footer', 'weight' => 40]);
      drupal_add_css($module_path . '/src/css/yamap.css');
      
      
      return [
        'content' => theme('main-yamap'),
      ];
    }
  }
?>

When I enable cache and aggregation, js falls off .. there are no errors on the page and in the console.

Drupal.settings.my_data does not exist too. But, if I turn off the block cache or aggregation, then everything is ok

-1

Is the site in D7 or D8/9?

Because in 8+ you should use #attached instead of drupal_add_js/css

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.