I want to see search results in list mode by default in desktop, and see it on grid mode on mobile.
What should I do?
Right now I edited catalog search list.phtml
to show list mode by default on search result page but on mobile, I see list mode too. I want to see grid mode on mobile.
Update from comment:
if ($block->getMode() == 'grid') {
$viewMode = 'list';
$image = 'category_page_list';
$showDescription = false;
$templateType =
\Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
} else {
$viewMode = 'grid';
$image = 'category_page_grid';
$showDescription = true;
$templateType =
\Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
}
but it works on any device, can not seperate them for devices
Best Answer
Update: Add an exception for mobile devices
Search strings are either normal strings or regular expressions (PCRE).
I hope it makes sense.
Please let me know if you have any related question.
Add "mobile" in search string and select any template you want to use for mobile, and its done. For all mobile devices automatically those templates will be taken.