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 changed. 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_pathagainst a path alias though, you should be running that against the router path, not URL path: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:
You don’t need to specify
'#type' => 'markup'asmarkupis 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