
MobileDetect snippet
Compares the current device type with parameter &input and returns 1 (match) or 0 (no match).
Important: call uncached — [[!MobileDetect]]. With cache the result is the same for all visitors.
Parameters
| Parameter | Description | Default |
|---|---|---|
&input | Expected type: standard, tablet, mobile | mobile |
Types match getDeviceType() from the MobileDetect service.
Examples
Mobile
modx
[[!MobileDetect:is=`1`:then=`
<p>Mobile content</p>
`:else=``:input=`mobile`]]fenom
{if $modx->runSnippet('MobileDetect', ['input' => 'mobile']) == 1}
<p>Mobile content</p>
{/if}Tablet
modx
[[!MobileDetect:is=`1`:then=`
<p>Tablet content</p>
`:else=``:input=`tablet`]]fenom
{if $modx->runSnippet('MobileDetect', ['input' => 'tablet']) == 1}
<p>Tablet content</p>
{/if}Desktop (standard)
modx
[[!MobileDetect:is=`1`:then=`
<p>Desktop content</p>
`:else=``:input=`standard`]]fenom
{if $modx->runSnippet('MobileDetect', ['input' => 'standard']) == 1}
<p>Desktop content</p>
{/if}Mobile / desktop branch
modx
[[!MobileDetect:is=`1`:then=`
[[$mobileHeader]]
`:else=`
[[$desktopHeader]]
`:input=`mobile`]]fenom
{if $modx->runSnippet('MobileDetect', ['input' => 'mobile']) == 1}
{$modx->getChunk('mobileHeader')}
{else}
{$modx->getChunk('desktopHeader')}
{/if}How it works
- Snippet loads the
MobileDetectservice - Reads forced mode GET parameter (
md_force_browser_variable) - Calls
resolveDevice()— cookie, GET, or User-Agent - Compares
$inputwith current type (case-insensitive) - Returns
(int) match
Placeholder [[+mobiledetect.device]] is set by the plugin, not the snippet.
Related
- Integration — Fenom and HTML tags
- System settings — GET parameters and cookie
- Troubleshooting — caching
