Frontend\Core\Engine\Header::addCSS PHP Method

addCSS() public method

Add a CSS file into the array
public addCSS ( string $file, boolean $minify = true, boolean $addTimestamp = null )
$file string The path for the CSS-file that should be loaded.
$minify boolean Should the CSS be minified?
$addTimestamp boolean May we add a timestamp for caching purposes?
    public function addCSS($file, $minify = true, $addTimestamp = null)
    {
        $file = (string) $file;
        $minify = (bool) $minify;
        $addTimestamp = (bool) $addTimestamp;
        // get file path
        if (mb_substr($file, 0, 4) != 'http') {
            $file = Theme::getPath($file);
        }
        // no minifying when debugging
        if ($this->getContainer()->getParameter('kernel.debug')) {
            $minify = false;
        }
        if ($minify) {
            $file = $this->minifyCSS($file);
        }
        $cssFile = array('file' => $file, 'add_timestamp' => $addTimestamp);
        // only add when not already in array
        if (!isset($this->cssFiles[$file])) {
            $this->cssFiles[$file] = $cssFile;
        }
    }

Usage Example

Example #1
0
 /**
  * Add a CSS file into the array
  *
  * @param string $file The path for the CSS-file that should be loaded.
  * @param bool $overwritePath Whether or not to add the module to this path. Module path is added by default.
  * @param bool $minify Should the CSS be minified?
  * @param bool $addTimestamp May we add a timestamp for caching purposes?
  */
 public function addCSS($file, $overwritePath = false, $minify = true, $addTimestamp = null)
 {
     // redefine
     $file = (string) $file;
     $overwritePath = (bool) $overwritePath;
     // use module path
     if (!$overwritePath) {
         $file = '/src/Frontend/Modules/' . $this->getModule() . '/Layout/Css/' . $file;
     }
     // add css to the header
     $this->header->addCSS($file, $minify, $addTimestamp);
 }