0

I want to add one css class when on search of a particular product we does not get any result see https://prnt.sc/oyh8h9 and https://prnt.sc/oyh90w. I want to add class in footer block based on the result for product search. Any idea.

0

The file you are looking for is this one:

/vendor/magento/module-catalog-search/view/frontend/templates/result.phtml

The conditional you need to check is this one:

<?php if ($block->getResultCount()): ?>

So if no count of results you can edit the response for it. Change HTML markup, etc.

What I don't quite follow is why you would change the footer? If that is the case, on the else in that conditional you can create a custom <script> and add something to the footer via JavaScript.

5
  • I want to add one css class to the footer block based on if else condition. how to add that through javascript?
    – Nafsss
    Aug 29 '19 at 4:47
  • You know that the footer block is not the same as "Your search returned no results", right? Footer means the bottom of your HTML markup. If that is the case, you need to add a custom script and call for a custom script. Here are some guides for you: devdocs.magento.com/guides/v2.3/javascript-dev-guide/javascript/… you need to use the imperative, create your require and create your custom function. Aug 29 '19 at 17:18
  • Good Luck! If that doesn't help, you really need first to go through the guides before moving forward. Aug 29 '19 at 17:19
  • This is fine, but can you tell me how can i add css class to static footer block from phtml file
    – Nafsss
    Aug 30 '19 at 11:03
  • Do you want the whole code for something javascript basic? I mean, check for the basics on how to add a javascript class with jquery in magento 2 preferable. Happy coding! Aug 30 '19 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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