As you have guessed yourself, the syntax {detect_device}
is different than {if detect_device == 'desktop'}
. The former calls the function "detect device", while the latter compares the string literal detect_device
against a value.
If you want to use a modifier, the correct way is this (manual):
{'isiOS'|detect_device}
Regarding caching the results, you don't have to store the Mobile_Detect object, but rather its result (the browser string). For this, you can use PHP's usual methods for persisting values: you can use the $GLOBALS
variable space, or, if you are using sessions, store the result in a session (which will be different if the user signs in using a different browser). Same goes with cookies.
The session/cookie approach is better in that it will cache the result throughout the user's session (or longer), not just once per page load