Skip to content

Instantly share code, notes, and snippets.

@mherchel
Last active January 4, 2023 16:40
Show Gist options
  • Save mherchel/b7d14cf49ec54550c90b091fe4f28bd0 to your computer and use it in GitHub Desktop.
Save mherchel/b7d14cf49ec54550c90b091fe4f28bd0 to your computer and use it in GitHub Desktop.

Create custom Gin styles

Steps

  1. Create a custom module (I'm calling mine mymodule) and place it in /modules/custom/mymodule
  2. Add the mymodule.module file and place in the custom mode
  3. Create the mymodule.libraries.yml file and place in the new library that points to the CSS
  4. Create the CSS file within a css directory. Name it the same thing that you have in the mymodule.libraries.yml (gin-global.css)
/* Custom Gin styles here. */
.my-gin-selector {
color: red;
}
gin-global:
css:
component:
css/gin-global.css: {}
/**
* Implements hook_preprocess_HOOK().
*/
function mymodule_custom_preprocess_html(&$variables, $hook) {
$activeThemeName = \Drupal::service('theme.manager')->getActiveTheme()->getName();
if ($activeThemeName === 'gin') {
$variables['#attached']['library'][] = 'mymodule/gin-global';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment