Extension:TemplateData/Template search widget
Appearance
This page is currently a draft.
|
- This feature is not yet available for use. See phabricator:tag/template-discovery-and-recall for current progress.
TemplateData provides an OOUI widget that can be used to search for and select a template title. It also handles storing a user's list of favourite templates, and other features that can help users find templates more easily.
For end-user help about using the widget, see Help:TemplateData/Template search widget .
Usage
[edit]TemplateSearchLayout
[edit]To create a template search widget:
const templateSearch = new mw.templateData.TemplateSearchLayout( {
allowNonExisting = true,
/* …and any other OO.ui.PanelLayout options */
} );
templateSearch.connect( this, { choose: function ( templateData ) {
// The templateData object contains info about the template
// that was selected, such as its title, description,
// notemplatedata, redirecttitle, etc.
} } );
To set the focus to the new widget:
templateSearch.focus();
FavoriteButton
[edit]A FavoriteButton takes care of favouriting and unfavouriting, and is initialized with whatever the state of the current user's favourites is.
To add a favourite button:
const faveButton = new mw.templateData.FavoriteButton( { pageId: aTemplatePageIdHere } );
$( '#somewhere-in-the-dom' ).append( faveButton.$element );
You can optionally pass in a FavoritesStore, using the favouritesStore
config key.