Normal PHP is deprecated in Smarty 3, do not use it!
You can use a library such as Mobile Discovery or Mobile Discovery Browsers .
Create a plugin in the plugins directory, function.detect_mobile.php :
function smarty_function_detect_mobile($params, &$smarty) { require_once './libraries/Mobile_Detect.php'; $detect=new Mobile_Detect; $smarty->assign('is_mobile', false); if($detect->isMobile()) { $smarty->assign('is_mobile', true); } }
Then use it in the template file:
{detect_mobile} {if $is_mobile} <link rel="stylesheet" href="css/styles-mobile.css" type="text/css" /> {else} <link rel="stylesheet" href="css/styles.css" type="text/css" /> {/if}
source share