2

I am doing a module in magento 2 and I need to have separate phtml files for desktop and mobile respectively.

How can I do that? Do I need to create a mobile template, that override the module and use user agent rules in the admin ?

If it is the the best way, how can I override the module/view/frontend/template/mytemplate.phtml ?

I am a bit lost here and any help would be greatly appreciated.

3
  • Do you mean make a website mobile reponsive or having a whole new layout? Oct 24, 2017 at 4:39
  • I need a new layout because will have different functionality (the mobile will interact with the camera) Oct 24, 2017 at 9:17
  • I'm sorry , have never seen that before. I mean you could just create another page with a Controller and then use Javascript to determine the device and redirect to the other page. Or you can just have 1 big template fille where you have a Desktop and a Mobile div in it and just hide/show the right div with css and media screen. Hmmn but i don't see a clean solution Oct 24, 2017 at 10:52

1 Answer 1

1

I tried different options but at the end to keep it easier to understand from the magento admin I added 2 themes desktop and mobile that override the module. I didn't needed to change the layout configuration in the modules.

module

app/code/acme/modulename/view/frontend/templates/main.phtml

desktop

app/design/acme_default/templates/main.phtml

mobile

app/design/acme_mobile/templates/main.phtml

Then added the acme_default at admin->content->design->configuration->edit Applided Theme

and added a new user agent rule for mobile with acme_moble

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.