I've created a custom module with two diverent stages for desktop and mobile. To make sure not run into SEO trubble because of duplicate content I try to find a solution to caputure the browser widow/screen size in Hubl and diliver just necessary code.
Thank you @Thomastechweb for your feedback! Your version works but unfortunately not that perfect in my case :-(.
My promblem in detail: An agency created several custom moduls for us which has two (other modules have three) different design stages one for desktop and one for mobile (and sometimes one also for tablet). With media quiries the different stages will switch so nothing special. The problem is that this modul crates a lot of duplicate content because both parts are loading in the code. Now I try to find a way to load just the moblie or the desktop part... Do you have any idea how to handle this?
Ok, it's diffcult to write the entire solution without seeing all you code. But here's a suggestion for mobile / desktop (not tablet) which should meet your needs:
If you change the code to and add it to the top your module:
{% set agent = request.headers['user-agent']|lower|string %}
{% set is_mobile = false %}
{% if agent is string_containing "mobile" || agent is string_containing "android" || agent is string_containing "iphone" %}
{% set is_mobile = true %}
{% endif %}
Then you can wrap your mobile / desktop specific content with simple IF tests:
If mobile, show this
{% if is_mobile %}
<div class="d-lg-none">
<!-- Only show on mobile -->
</div>
{% endif %}
If not mobile show
{% if !is_mobile %}
<div class="d-none d-lg-block">
<!-- Only show on desktop -->
</div>
{% endif %}
I think the main problem is the user-agent. I've no idea how to handle changes in these agentes in future... I think i will run in a lot of problem with this 😞