{detect}

Description

Detects the visitor device class from the browser User-Agent and returns one of three bare words: mobile, tablet, or desktop. Call it with no parameter. A server-side render with no mobile browser - the documentation test harness, search-engine crawlers, plain HTTP clients - reports desktop. Pair it with ifeq or switch to choose a layout per device. The one parameter is reserved for a future test selector and is not implemented; passing any value returns an empty string. The result is cached without the User-Agent in the cache key, so on a cached page the first visitor's device type may be served to others - render with nocache or clear the cache when per-device output must stay accurate.

Parameters

test optional

Reserved for a future test-type selector and not implemented yet. Leave it empty and call the command as detect with no parameter. Supplying any value makes the command return an empty string.

Examples

test{detect}
Expecteddesktop
Actualdesktop
The parameterless form returns the device class as a bare word: mobile, tablet, or desktop. A server-side render with no mobile browser (the documentation test harness, search-engine crawlers, plain HTTP clients) reports desktop.
test[{detect}]
Expected[desktop]
Actual[desktop]
The brackets make the exact output visible: the command returns just the word, with no surrounding spaces.
test{ifeq:{detect}:mobile:compact menu:full menu}
Expectedfull menu
Actualfull menu
Typical use: pick a layout by device. Because the harness reports desktop, the else branch (full menu) is chosen; on a phone the result would be compact menu.
test{switch({detect})mobile:phone layout:tablet:tablet layout:desktop layout}
Expecteddesktop layout
Actualdesktop layout
Handle all three device classes at once. The paren form of switch lets the condition come from another command. Here detect reports desktop, so the trailing default (desktop layout) is returned.
test[{detect:tablet}]
Expected[]
Actual[]
The single parameter is reserved for a future test-type selector and is not implemented. Passing any non-empty value makes the command return an empty string, so always call it with no parameter.
virtual{detect}
Expected(mobile on a phone, tablet on a tablet, desktop otherwise)
Actualdesktop
The real value is computed from the visitor User-Agent at request time, so it varies per visitor. Note: the result is cached without the User-Agent in the cache key, so on a cached page the first visitor's device type can be served to everyone - render with nocache or clear the cache when this matters.