Semantic-ui: Custom Templates for Search

Created on 21 Mar 2015  路  6Comments  路  Source: Semantic-Org/Semantic-UI

It'd be great to be able to use custom templates for the search module. It might work well to spec a template like this:

$(".ui.search").search({
   ...
   template: "myTemplate"
});

<div class="template">
   <h1>{{title}}</h1>
</div>

If this already exists and I missed it, apologies. Didn't see anything like this in the docs, tho.

Docs Issue

Most helpful comment

You can modify search templates by altering $.fn.search.settings.templates.

They are currently simple JS concatenated strings, but could also work with compiled handlebar templates, although i haven't tested

If you wanted to overwrite default template just overwrite $.fn.search.settings.template.standard

If you want to overwrite the message template modify $.fn.search.settings.templates.message

If you want to add your own template just specify a new template name as type on init.

For example

$.fn.search.settings.templates.special = function(response) {
 // do something with response
  return html;
};

$('.ui.search')
  .search({
    type: 'special'
  })
;

You can also specify on element init, but you'd have to do this each time.

$('.ui.search')
  .search({
    type: 'special'
    templates: {
      special: function(response){

      }
  })
;

All 6 comments

You can modify search templates by altering $.fn.search.settings.templates.

They are currently simple JS concatenated strings, but could also work with compiled handlebar templates, although i haven't tested

If you wanted to overwrite default template just overwrite $.fn.search.settings.template.standard

If you want to overwrite the message template modify $.fn.search.settings.templates.message

If you want to add your own template just specify a new template name as type on init.

For example

$.fn.search.settings.templates.special = function(response) {
 // do something with response
  return html;
};

$('.ui.search')
  .search({
    type: 'special'
  })
;

You can also specify on element init, but you'd have to do this each time.

$('.ui.search')
  .search({
    type: 'special'
    templates: {
      special: function(response){

      }
  })
;

Awesome, thanks for that info. I'll go that route. Should I leave this open so it makes its way into the docs at some point?

Yes

Added to 2.0 docs with explanation

Should not these settings be found on the settings page?

I tried to use custom template (using items). But I can't control dropdown size. How to solve this?
screenshot 2017-11-12 16 15 19

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rdzidziguri picture rdzidziguri  路  3Comments

vinhtq picture vinhtq  路  3Comments

mllamazares picture mllamazares  路  3Comments

Morrolan picture Morrolan  路  3Comments

ghost picture ghost  路  3Comments