How to call different templates for Desktop and Mobile in Prestashop (Smarty)

You can easily detect for Desktop and mobile devices with below script in Controller file of prestashop.


require_once(_PS_TOOL_DIR_.'mobile_Detect/Mobile_Detect.php');
$this->mobile_detect = new Mobile_Detect();
$mobile_class = 'desktop';
if ($this->mobile_detect->isMobile() && !$this->mobile_detect->isTablet()){
  $mobile_class = 'mobile';
 }
// Call Different file for desktop and mobile
if ($mobile_class == 'desktop'){
 $template_name  = 'postcategory.tpl';
} else {
 $template_name  = 'postcategorymobile.tpl';
}
// And finally setTemplate HTML.
$this->setTemplate($template_name );

Post a Comment

1 Comments

  1. This is a great post and I read a way while back. It really helped me out.Thank you so much for this great article.
    SEO Tool
    wordpress theme

    ReplyDelete