Requirements_Backend
class Requirements_Backend (View source)
Properties
protected | bool | $suffix_requirements | Whether to add caching query params to the requests for file-based requirements. |
|
protected | bool | $combined_files_enabled | Whether to combine CSS and JavaScript files |
|
protected | array | $javascript | Paths to all required JavaScript files relative to docroot |
|
protected | array | $css | Paths to all required CSS files relative to the docroot. |
|
protected | array | $customScript | All custom javascript code that is inserted into the page's HTML |
|
protected | array | $customCSS | All custom CSS rules which are inserted directly at the bottom of the HTML tag |
|
protected | $customHeadTags | All custom HTML markup which is added before the closing tag, e.g. additional metatags. |
||
protected | array | $disabled | Remembers the file paths or uniquenessIDs of all Requirements cleared through clear(), so that they can be restored later. |
|
protected | array | $blocked | The file paths (relative to docroot) or uniquenessIDs of any included requirements which should be blocked when executing inlcudeInHTML(). This is useful, for example, to block scripts included by a superclass without having to override entire functions and duplicate a lot of code. |
|
public | array | $combine_files | A list of combined files registered via combine_files(). Keys are the output file names, values are lists of input files. |
|
public | bool | $combine_js_with_jsmin | Use the JSMin library to minify any javascript file passed to combine_files(). |
|
public | bool | $write_header_comment | Whether or not file headers should be written when combining files |
|
protected | string | $combinedFilesFolder | Where to save combined files. By default they're placed in assets/_combinedfiles, however this may be an issue depending on your setup, especially for CSS files which often contain relative paths. |
|
public | bool | $write_js_to_body | Put all JavaScript includes at the bottom of the template before the closing tag, rather than the default behaviour of placing them at the end of the tag. This means script downloads won't block other HTTP requests, which can be a performance improvement. |
|
protected | bool | $force_js_to_bottom | Force the JavaScript to the bottom of the page, even if there's a script tag in the body already |
Methods
Enable or disable the combination of CSS and JavaScript files
Set the folder to save combined files in. By default they're placed in assets/_combinedfiles, however this may be an issue depending on your setup, especially for CSS files which often contain relative paths.
Set whether to add caching query params to the requests for file-based requirements.
Set whether you want to write the JS to the body of the page rather than at the end of the head tag.
Forces the JavaScript requirements to the end of the body, right before the closing tag
Register the given JavaScript code into the list of requirements
Register the given CSS styles into the list of requirements
Add the following custom HTML code to the
section of the pageInclude the content of the given JavaScript file in the list of requirements. Dollar-sign variables will be interpolated with values from $vars similar to a .ss template.
Register the given stylesheet into the list of requirements.
Update the given HTML content with the appropriate include tags for the registered requirements. Needs to receive a valid HTML/XHTML template in the $content parameter, including a head and body tag.
Remove all newlines from code to preserve layout
Safely escape a literal string for use in preg_replace replacement
Attach requirements inclusion to X-Include-JS and X-Include-CSS headers on the given HTTP Response
Add i18n files from the given javascript directory. SilverStripe expects that the given directory will contain a number of JavaScript files named by language: en_US.js, de_DE.js, etc.
Concatenate several css or javascript files into a single dynamically generated file. This increases performance by fewer HTTP requests.
Return all combined files; keys are the combined file names, values are lists of files being combined.
Delete all dynamically generated combined files from the filesystem
Deletes all generated combined files in the configured combined files directory, but doesn't delete the directory itself.
Do the heavy lifting involved in combining (and, in the case of JavaScript minifying) the combined files.
Minify the given $content according to the file type indicated in $filename
Registers the given themeable stylesheet as required.
Registers the given themeable javascript as required.
Details
set_combined_files_enabled($enable)
Enable or disable the combination of CSS and JavaScript files
bool
get_combined_files_enabled()
Check whether file combination is enabled.
setCombinedFilesFolder(string $folder)
Set the folder to save combined files in. By default they're placed in assets/_combinedfiles, however this may be an issue depending on your setup, especially for CSS files which often contain relative paths.
string
getCombinedFilesFolder()
No description
set_suffix_requirements($var)
Set whether to add caching query params to the requests for file-based requirements.
Eg: themes/myTheme/js/main.js?m=123456789. The parameter is a timestamp generated by filemtime. This has the benefit of allowing the browser to cache the URL infinitely, while automatically busting this cache every time the file is changed.
bool
get_suffix_requirements()
Check whether we want to suffix requirements
set_write_js_to_body($var)
Set whether you want to write the JS to the body of the page rather than at the end of the head tag.
set_force_js_to_bottom($var)
Forces the JavaScript requirements to the end of the body, right before the closing tag
javascript(string $file)
Register the given JavaScript file as required.
array
get_javascript()
Returns an array of all required JavaScript
customScript(string $script, string|int $uniquenessID = null)
Register the given JavaScript code into the list of requirements