I want to use this mobile php file detector on the magento website, and I want to know that this is the best way to insert a php file and use it through other subtopics, since the magento structure is still a bit complicated for me.
Basically I have something like this main-template.phtml and header.phtml
main-template.phtml content
<?php include_once 'Mobile_Detect.php'; $detect = new Mobile_Detect(); echo $this->getChildHtml('head'); ?> <?php if ( $detect->isMobile() ) { <meta name="mobileMain" content="this is for mobile"> <?php } else {?> <meta name="NOTmobileMAIN" content="this is not for mobile"> <?php } ?>
Header.phtml content
<?php if ( $detect->isMobile() ) { <meta name="mobile" content="this is for mobile"> <?php } else {?> <meta name="NOTmobile" content="this is not for mobile"> <?php } ?>
When I load main-template.phtml in a browser, the second condition works, but the first throws an error "Calling a member function isMobile () for a non-object".
What would be the best way to include Mobile_Detect.php only once in my main-template.phtml and then be able to run this condition in all my subfiles, such as header.phtml, which will also be inserted into the main template. PHTML?
Thanks!
octasimo
source share