How to detect mobile viewport with in twig? Is there a way to detect screen display with in twig? I have a block and I want to render in a twig template using the twig tweak module, but only in mobile screen. It is surely possible to just hide it in CSS, but can it be done in twig? - https://www.drupal.org/project/twig_tweak
There is a Browser Object in twig which using that you can get some data about user's browser but it does not provide properties like screen width.

its recommended to use css or javascript in these situations but if you want to hide your block in server side so user might access only using a mobile phone then I recommend this steps:


first of all you should provide a value to check if user is using mobile or not, for this you should use a preprocess function (hook_preprocess_page I guess as will fire for any pages loaded) , there use a code like this to detect mobile, then add a boolean value to page which should be TRUE if user is using mobile.
after that in twig you will have that value, check if it is true and display your block