On this page
Theming the ReactJS search app
Last updated on
19 December 2018
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
There are many ways to create a custom search app theme. The two that we recommend are:
- Cloning the search app repo and working in the development environment (perhaps faster, especially if you're familiar/comfortable with things like
gitandyarn)- Clone Federated Search React
- Move into the repo root
cd federated-search-reach - Install dependencies
yarn install - Configure your solr backend
- Copy
./src/.env.local.js.exampleinto./src/.env.local.js - Configure your solr backend url in
./src/.env.local.js
- Copy
- Spin up the dev instance
yarn start - Open the project in your IDE or code editor
- Start making changes to
./theme/search_theme_override(Protip: make sure you uncomment any of the changes you make by removing the beginning//) - Save your changes and go back to the search app in your browser, the app should reload each time you press save
- Once you've got the app themed, you can either use
./theme/search_theme_override.scssin your site themesassworkflow or grab the./public/css/search_theme_override.cssfile and add it to your theme styles (see below).
- Theming the search app in the context of your Drupal site (perhaps longer, but perfectly okay, especially if your site has a scss/css workflow that you're comfortable with)
- For themes with SASS: Copy
./docs/assets/search_theme_override.scssfrom this module and add it to your theme sass files and start making changes. - For themes with CSS only: Copy
./docs/assets/search_theme_override.cssfrom this module and add it to your theme css files and start making changes. - You'll likely also need to define this css file as a theme library and attach it to the search page (See below).
- For themes with SASS: Copy
Adding the styles to your theme
Once you have defined your theme styles, we recommend adding the CSS to your theme directory and attaching that file to the search page route.
Assuming that your search theme css file exists at /css/search_theme_override.css, you can update your theme template.php with:
// <your-theme>/template.php file
// =====================================
/**
* Override or insert variables into the page templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("page" in this case.)
*/
function <your-theme>_preprocess_page(&$variables, $hook) {
// Add search theme override css to the search app path.
$path = current_path();
$search_path = variable_get('search_api_federated_solr_path', 'search-app');
if ($search_path && $search_path === $path) {
drupal_add_css(drupal_get_path('theme', '<your-theme>') . '/css/search_theme_override.css', array('group' => CSS_THEME));
}
}Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion