Skip to content

Instantly share code, notes, and snippets.

@sheadawson
Created June 18, 2015 01:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheadawson/de773517531d61ea39bf to your computer and use it in GitHub Desktop.
Save sheadawson/de773517531d61ea39bf to your computer and use it in GitHub Desktop.
SilverStripe Custom Requirements - put css and js file contents into the page
<?php
class Page_Controller extends ContentController{
/**
* Require a custom script from a file
* @param string $filepath
* @param bool $addMinLive - prepend .min to file extension if not in dev mode
*/
public function inlineJS($filepath, $addMinLive = true){
if(($addMinLive || $addMinLive != 'false') && !Director::isDev()) $filepath = str_replace('.js', '.min.js', $filepath);
$filepath = BASE_PATH . '/' . $filepath;
if(file_exists($filepath)){
Requirements::customScript(file_get_contents($filepath), $filepath);
}
}
/**
* Require custom css from a file
* @param string $filepath
* @param bool $addMinLive - prepend .min to file extension if not in dev mode
*/
public function inlineCSS($filepath, $addMinLive = true){
if(($addMinLive || $addMinLive != 'false') && !Director::isDev()) $filepath = str_replace('.css', '.min.css', $filepath);
$filepath = BASE_PATH . '/' . $filepath;
if(file_exists($filepath)){
Requirements::customCSS(file_get_contents($filepath), $filepath);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment