1

我正在为我们的展示广告代码使用DFP Drupal 模块。我想通过预处理将另一个模块提供的附加 JavaScript 附加到每个 DFP 块。那可能吗?我想避免通过主题这样做。

4

2 回答 2

1

要在您的预处理函数中添加 js,请使用drupal_add_js,有关更多详细信息,请参阅此链接

于 2013-04-19T04:19:47.500 回答
0

您可以使用以下代码来实现:

function MYTHEME_preprocess_block(&$vars) {

    $block_id = $vars['block']->module . '-' . $vars['block']->delta;
    // Use the following to inspect the ids of the active blocks in a given page
    drupal_set_message($block_id);

    switch ($block_id) {
    case 'block-12': // block id of the target
        drupal_add_css(drupal_get_path('module', 'my_module') . '/css/my-block.css');
        break;
    }
}
于 2017-02-06T19:41:41.810 回答