how to detect screen size or mobile/desktop using twig how to detect screen size or mobile/desktop using twig symfony symfony

how to detect screen size or mobile/desktop using twig


You can use MobileDetectBundle for detecting mobile devices, manage mobile view and redirect to the mobile and tablet version

Twig Helper

{% if is_mobile() %}{% if is_tablet() %}{% if is_device('iphone') %} # magic methods is[...]

Twig examples

{% if is_mobile_view() %}    {% extends "MyBundle:Layout:mobile.html.twig" %}{% else if is_tablet_view() %}    {% extends "MyBundle:Layout:tablet.html.twig" %}{% else if is_full_view() or is_not_mobile_view() %}    {% extends "MyBundle:Layout:full.html.twig" %}{% endif %}