class Requirements_Backend (View source)

Properties

array $combine_files

A list of combined files registered via {@link combine_files()}. Keys are the output file names, values are lists of input files.

bool $combine_js_with_jsmin

Use the JSMin library to minify any javascript file passed to {@link combine_files()}.

bool $write_header_comment

Whether or not file headers should be written when combining files

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.

Methods

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.

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

array
get_custom_scripts()

Return all registered custom scripts

customCSS(string $script, string|int $uniquenessID = null)

Register the given CSS styles into the list of requirements

insertHeadTags(string $html, string|int $uniquenessID = null)

Add the following custom HTML code to the section of the page

javascriptTemplate(string $file, string[]|int[] $vars, string|int $uniquenessID = null)

Include 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.

css(string $file, string $media = null)

Register the given stylesheet into the list of requirements.

array
get_css()

Get the list of registered CSS file requirements, excluding blocked files

clear(string|int $fileOrID = null)

Clear either a single or all requirements

restore()

Restore requirements cleared by call to Requirements::clear

block(string|int $fileOrID)

Block inclusion of a specific file

unblock(string|int $fileOrID)

Remove an item from the block list

unblock_all()

Removes all items from the block list

string
includeInHTML(string $templateFile, string $content)

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.

include_in_response(SS_HTTPResponse $response)

Attach requirements inclusion to X-Include-JS and X-Include-CSS headers on the given HTTP Response

array
add_i18n_javascript(string $langDir, bool $return = false, bool $langOnly = false)

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.

bool|void
combine_files(string $combinedFileName, array $files, string $media = null)

Concatenate several css or javascript files into a single dynamically generated file. This increases performance by fewer HTTP requests.

array
get_combine_files()

Return all combined files; keys are the combined file names, values are lists of files being combined.

delete_combined_files(string $combinedFileName = null)

Delete all dynamically generated combined files from the filesystem

delete_all_combined_files()

Deletes all generated combined files in the configured combined files directory, but doesn't delete the directory itself.

clear_combined_files()

Clear all registered CSS and JavaScript file combinations

process_combined_files()

Do the heavy lifting involved in combining (and, in the case of JavaScript minifying) the combined files.

themedCSS(string $name, string $module = null, string $media = null)

Registers the given themeable stylesheet as required.

themedJavascript(string $name, string $module = null, string $type = null)

Registers the given themeable javascript as required.

debug()

Output debugging information.

Details

set_combined_files_enabled($enable)

Enable or disable the combination of CSS and JavaScript files

Parameters

$enable

bool get_combined_files_enabled()

Check whether file combination is enabled.

Return Value

bool

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.

Parameters

string $folder

string getCombinedFilesFolder()

Return Value

string

Folder relative to the webroot

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.

Parameters

$var

bool get_suffix_requirements()

Check whether we want to suffix requirements

Return Value

bool

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.

Parameters

$var

set_force_js_to_bottom($var)

Forces the JavaScript requirements to the end of the body, right before the closing tag

Parameters

$var

javascript(string $file)

Register the given JavaScript file as required.

Parameters

string $file

Relative to docroot

array get_javascript()

Returns an array of all required JavaScript

Return Value

array

customScript(string $script, string|int $uniquenessID = null)

Register the given JavaScript code into the list of requirements

Parameters

string $script

The script content as a string (without enclosing