Search code examples
jquery-select2smartyshopware

How to add Select2 to a smarty template in Shopware 5 plugin?


I would like to add select2 to a smarty template in a shopware 5 plugin, in order to be able to type and search for a value in the dropdown. I was searching for it but found nothing relevant. As I see, there is only a standard <select> which is a html select, and {html_options} there is no way to type and search for what you are looking for in the dropdown, right? Is it possible to add select2 to smarty? If yes, could you please pont me to the rigth direction? If it's not possible or too complicated, what would be a better alternative? Is it possible in Shopware 6? (I wanted to ask this question actually on stack exchange, but I can't...)


Solution

  • Unfortunately you did not mention what you try so far.

    I believe you have to add the Javascript resources as in https://select2.org/getting-started/installation and add the .select2() call in the on ready.

    The HTML of the select can stay the same - the select2 script will transform this.