开发者

altering footer page on drupal 7

开发者 https://www.devze.com 2023-04-11 19:38 出处:网络
In Drupal 6, my module had this next function which inserted a javascript to the footer of the page, but in Drupal 7, stuff have chan开发者_如何学编程ged. How can I do this next code in drupal 7?

In Drupal 6, my module had this next function which inserted a javascript to the footer of the page, but in Drupal 7, stuff have chan开发者_如何学编程ged. How can I do this next code in drupal 7?

function myfunc_footer()
 {
    if(variable_get('myvar',1) && !drupal_match_path(drupal_get_path_alias($_GET['q']),  
          'admin/*'))
    {
         if ($somevar = variable_get('somevar',''))
             {
        return '<script src="'.$somevar.'" type="text/javascript"></script>';
         }
         else
             {
        drupal_set_message(t('something is wrong.'));
         }
    }
}

Thanks in advance


Nothing in your code has changed from Drupal 6 to 7...all of the functions are valid and if this worked for Drupal 6 there's no reason it wouldn't work for Drupal 7.

I don't really understand why you're running drupal_match_path against a path alias though, you should be running that against the router path, not URL path:

if(variable_get('myvar',1) && !drupal_match_path($_GET['q'], 'admin/*')) {

Try that and see if it fixes your problem, if not could you expand a bit about what error you're getting?

EDIT

Thanks for the update, your second comment below is nearly right, you just need to give the render array a key:

function myfunc_page_alter(&$page) { 
  $page['page_bottom']['my_extra_element'] = array(
    '#markup' => '<div><h3> testingthisout</h3> </div>', 
    '#weight' => 25
  ); 
} 

You don't need to specify '#type' => 'markup' as markup is the default.

Then make sure your module (the one called myfunc) is definitely installed, and clear the caches. You shouldn't have any problems from there

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号