Created
June 18, 2015 01:34
-
-
Save sheadawson/de773517531d61ea39bf to your computer and use it in GitHub Desktop.
SilverStripe Custom Requirements - put css and js file contents into the page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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