This project is not covered by Drupal’s security advisory policy.

This module give you the ability to add dynamic css / js to your website.
After adding this module you can define dynamic options in your assets and define it's route to load them dynamically.

my_module.libraries.yml

core:
  version: VERSION
  js:
    dynamic_script: {type: dynamic, route: my_module.script}
  css:
    theme:
      css/fonts.css: {}
      dyanmic_style: {type: dynamic, route: my_module.style}

my_module.routing.yml

my_module.style:
  path: '/my_module/style.css'
  defaults:
    _controller: '\Drupal\my_module\Controller\AssetController::style'
    _title: 'color'
  requirements:
    _permission: 'access content'


my_module.script:
  path: '/my_module/script.js'
  defaults:
    _controller: '\Drupal\my_module\Controller\AssetController::script'
    _title: 'color'
  requirements:
    _permission: 'access content'

It also has a base DynamicAssetBaseController to help you with rendering css and js.

Drupal\my_module\Controller\AssetController

<?php

namespace Drupal\my_module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\dynamic_asset\Controller\DynamicAssetBaseController;
use Symfony\Component\HttpFoundation\Response;

/**
 * Class ColorController.
 */
class AssetController extends DynamicAssetBaseController {

  /**
   * Render styles.
   */
  public function style() {
    return $this->css([
      'h1, h2' => [
        'color' => 'red !important'
      ]
    ]);
  }


  /**
   * Render scripts.
   */
  public function script() {
    return $this->js('console.log("Dynamic Asset Working");');
  }

}

Project information

  • caution Seeking new maintainer
    The current maintainers are looking for new people to take ownership.
  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • Project categories: Developer tools
  • chart icon1 site reports using this module
  • Created by lostkoder on , updated
  • shield alertThis project is not covered by the security advisory policy.
    Use at your own risk! It may have publicly disclosed vulnerabilities.

Releases