Thanks for your response @wbmnfktr … I am aware that these things can be done with css/js … I was more interested in trying something outside my familiarity with php.
Here's a follow-up question: how can I write a custom function and access it in a template file in Processwire?
Inside of _init.php I have added a user-agent regex for mobile detection
<?php namespace ProcessWire;
// Optional initialization file, called before rendering any template file.
// This is defined by $config->appendTemplateFile in /site/config.php.
// Use this to define shared variables, functions, classes, includes, etc.
function isMobileDevice() {
// Get the user agent string
$userAgent = $_SERVER['HTTP_USER_AGENT'];
// Check if the user agent matches any common patterns for mobile devices
if (preg_match('/android|iphone|ipod|blackberry|iemobile|opera mobile|palmos|webos/i', $userAgent)) {
return true;
} else {
return false;
}
}
So why do I get: Call to undefined function isMobileDevice()
when trying to access this function with inside of a .latte template: {if isMobileDevice()}
I might be missing something very simple. This is some new territory for me.
With thanks,