Page 1 of 1

How to know if we are on the mobile page from a block ?

Posted: Fri Dec 08, 2017 11:13 pm
by polbrieuc
Hi all,

Inside a block, I need to know if I am on the mobile or desktop page.
I tried to put a variable $isMobile = true; in the indexMobile.php but it is not recognized in my block.
Is there a global variable accessible from insde a block that let me know if I am on the mobile page ?
If not, is there another way to test it from PHP?
I found a dirty way to test it in javascript but I would need it in PHP
Javascript way :

Code: Select all

	var pathname = window.location.pathname; 
	var indexMobile      = 'indexMobile';     
	if(pathname.indexOf(indexMobile) !== -1) {
	// do something ..
	}
Thanks for your help.

Re: How to know if we are on the mobile page from a block ?

Posted: Sat Dec 09, 2017 12:27 pm
by Jachym
Hi,
I think not, the problem is that the blocks are separate, they are loaded by the homepage by Javascript. So using PHP is probably impossible because you dont know which script will call it, this only happens after the homepage is being loaded and this is done by Javascript via Ajax request. This would require modification in the index files and adding it as a parameter in the Ajax call.