Drupal - How to customize the default search block form template?
The search block is provided by the core module Search. If you install this module the block will be available in the block layout, when you place a block.
Probably you have already done this by installing the standard profile.
To customize the search form you can use a form alter hook.
For example put this function in mytheme.theme
to change the search button:
function mytheme_form_alter(&$form, $form_state) {
if ( $form['#form_id'] == 'search_block_form' ) {
$form['actions']['submit']['#value'] = t('Search my Website');
}
}
If you want to use Twig, you can do it by creating a template file, like this:
/themes/your_theme/templates/form--search-block-form.html.twig
{% set form = element %}
hello {{ form.keys }} world {{ form.actions }}
Result:
In Bartik theme: