My goal is to render a warning message to IE 11 users, prompting them to use a modern browser.
I'm a bit of a noob, but from what I understand, it's possible to detect a user's browser using a preprocess function. I found this function online, which looks like it does what I need it to do, but I'm getting a "The website encountered an unexpected error. Please try again later." error when I add it to my THEMENAME.theme file.
function THEMENAME_preprocess(&$variables, $hook){
if (get_browser_name(htmlentities($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, 'UTF-8')) == 'Internet Explorer'){
$variables['browserIs'] = 'IE';
}
else{
$variables['browserIs'] = 'OTHERS';
}
}
Any ideas on how I can accomplish what I need?