MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/.trash/dist/select2/docs/_includes/options/selections/templating.html
<section>
  <h2 id="templateSelection">
    How can I customize the way selections are displayed?
  </h2>

  <p>
    When a selection is made by the user Select2 will display the text of the option by default, just like how it is displayed in a standard select box.  You can override the display of the selection by setting the <code>templateSelection</code> option to a JavaScript function.
  </p>

{% highlight js linenos %}
function template(data, container) {
  return data.text;
}

$('select').select2({
  templateSelection: template
});
{% endhighlight %}

  <h3>
    Nothing is being displayed when I select an option
  </h3>

  {% include options/not-written.html %}

  <h3>
    I am using HTML in my selection template but it isn't displaying it
  </h3>

  {% include options/not-written.html %}

  <h3>
    How can I access the container where the selection is displayed?
  </h3>

  {% include options/not-written.html %}
</section>