Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
page_requirements_manager Class Reference

This class tracks all the things that are needed by the current page. More...

Inheritance diagram for page_requirements_manager:

Public Member Functions

 __construct ()
 Page requirements constructor.
 
 css ($stylesheet)
 Ensure that the specified CSS file is linked to from this page.
 
 css_theme (moodle_url $stylesheet)
 Add theme stylesheet to page - do not use from plugin code, this should be called only from the core renderer!
 
 data_for_js ($variable, $data, $inhead=false)
 !!!!!!DEPRECATED!!!!!! please use js_init_call() for everything now.
 
 event_handler ($selector, $event, $function, array $arguments=null)
 Creates a YUI event handler.
 
 get_config_for_javascript (moodle_page $page, renderer_base $renderer)
 Return the safe config values that get set for javascript in "M.cfg".
 
 get_end_code ()
 Generate any HTML that needs to go at the end of the page.
 
 get_head_code (moodle_page $page, core_renderer $renderer)
 Generate any HTML that needs to go inside the <head> tag.
 
 get_jsrev ()
 Determine the correct JS Revision to use for this load.
 
 get_top_of_body_code (renderer_base $renderer)
 Generate any HTML that needs to go at the start of the <body> tag.
 
 has_one_time_item_been_created ($thing)
 Has a particular bit of HTML that is only required once on this page (e.g.
 
 is_head_done ()
 Have we already output the code in the <head> tag?
 
 is_top_of_body_done ()
 Have we already output the code at the start of the <body> tag?
 
 jquery ()
 Request inclusion of jQuery library in the page.
 
 jquery_override_plugin ($oldplugin, $newplugin)
 Request replacement of one jQuery plugin by another.
 
 jquery_plugin ($plugin, $component='core')
 Request inclusion of jQuery plugin.
 
 js ($url, $inhead=false)
 Ensure that the specified JavaScript file is linked to from this page.
 
 js_amd_inline ($code)
 This function appends a block of code to the AMD specific javascript block executed in the page footer, just after loading the requirejs library.
 
 js_call_amd ($fullmodule, $func=null, $params=array())
 Load an AMD module and eventually call its method.
 
 js_function_call ($function, array $arguments=null, $ondomready=false, $delay=0)
 !!!DEPRECATED!!! please use js_init_call() if possible Ensure that the specified JavaScript function is called from an inline script somewhere on this page.
 
 js_init_call ($function, array $extraarguments=null, $ondomready=false, array $module=null)
 Ensure that the specified JavaScript function is called from an inline script from page footer.
 
 js_init_code ($jscode, $ondomready=false, array $module=null)
 Add short static javascript code fragment to page footer.
 
 js_module ($module)
 Append YUI3 module to default YUI3 JS loader.
 
 set_one_time_item_created ($thing)
 Indicate that a particular bit of HTML that is only required once on this page (e.g.
 
 set_yuicssmodules (array $modules=array())
 Set the CSS Modules to be included from YUI.
 
 should_create_one_time_item_now ($thing)
 Should we generate a bit of content HTML that is only required once on this page (e.g.
 
 skip_link_to ($target, $linktext)
 Ensure that a skip link to a given target is printed at the top of the <body>.
 
 string_for_js ($identifier, $component, $a=null)
 Make a language string available to JavaScript.
 
 strings_for_js ($identifiers, $component, $a=null)
 Make an array of language strings available for JS.
 
 yui_module ($modules, $function, array $arguments=null, $galleryversion=null, $ondomready=false)
 Creates a JavaScript function call that requires one or more modules to be loaded.
 

Protected Member Functions

 find_module ($component)
 Find out if JS module present and return details.
 
 get_amd_footercode ()
 Returns js code to load amd module loader, then insert inline script tags that contain require() calls using RequireJS.
 
 get_css_code ()
 Returns html tags needed for inclusion of theme CSS.
 
 get_event_handler_code ()
 Returns code needed for registering of event handlers.
 
 get_extra_modules_code ()
 Adds extra modules specified after printing of page header.
 
 get_javascript_code ($ondomready)
 Get the inline JavaScript code that need to appear in a particular place.
 
 get_javascript_init_code ()
 Returns js code to be executed when Y is available.
 
 get_jquery_headcode ()
 Return jQuery related markup for page start.
 
 get_templaterev ()
 Determine the correct Template revision to use for this load.
 
 get_yui3lib_headcode ()
 Returns basic YUI3 JS loading code.
 
 get_yui3lib_headcss ()
 Returns basic YUI3 CSS code.
 
 init_requirements_data (moodle_page $page, core_renderer $renderer)
 Initialise with the bits of JavaScript that every Moodle page should have.
 
 js_fix_url ($url)
 Returns the actual url through which a JavaScript file is served.
 
 js_module_loaded ($module)
 Returns true if the module has already been loaded.
 

Protected Attributes

array $amdjscode = array('')
 Inline scripts using RequireJS module loading.
 
array $cssthemeurls = array()
 of moodle_url Theme sheets, initialised only from core_renderer
 
array $cssurls = array()
 of moodle_url List of custom theme sheets, these are strongly discouraged! Useful mostly only for CSS submitted by teachers that is not part of the theme.
 
array $eventhandlers = array()
 List of requested event handlers.
 
array $extramodules = array()
 Extra modules.
 
bool $headdone = false
 Flag indicated head stuff already printed.
 
array $jquerypluginoverrides = array()
 list of jQuery plugin overrides
 
array $jqueryplugins = array()
 list of requested jQuery plugins
 
array $jscalls = array('normal'=>array(), 'ondomready'=>array())
 List of needed function calls.
 
array $jsincludes = array('head'=>array(), 'footer'=>array())
 Included JS scripts.
 
array $jsinitcode = array()
 Javascript code used for initialisation of page, it should be relatively small.
 
array $jsinitvariables = array('head'=>array(), 'footer'=>array())
 List of JS variables to be initialised.
 
array $M_cfg
 Some config vars exposed in JS, please no secret stuff there.
 
array $onetimeitemsoutput = array()
 trackes the names of bits of HTML that are only required once per page.
 
array $skiplinks = array()
 List of skip links, those are needed for accessibility reasons.
 
array $stringsforjs = array()
 List of string available from JS.
 
array $stringsforjs_as = array()
 List of get_string $a parameters - used for validation only.
 
bool $topofbodydone = false
 Flag indicating top of body already printed.
 
stdClass $yui3loader
 YUI PHPLoader instance responsible for YUI3 loading from PHP only.
 
YUI_config $YUI_config
 default YUI loader configuration
 
array $yuicssmodules = array()
 $yuicssmodules
 

Detailed Description

This class tracks all the things that are needed by the current page.

Normally, the only instance of this class you will need to work with is the one accessible via $PAGE->requires.

Typical usage would be

    $PAGE->requires->js_call_amd('mod_forum/view', 'init');

It also supports obsoleted coding style with/without YUI3 modules.

    $PAGE->requires->js_init_call('M.mod_forum.init_view');
    $PAGE->requires->css('/mod/mymod/userstyles.php?id='.$id); // not overridable via themes!
    $PAGE->requires->js('/mod/mymod/script.js');
    $PAGE->requires->js('/mod/mymod/small_but_urgent.js', true);
    $PAGE->requires->js_function_call('init_mymod', array($data), true);

There are some natural restrictions on some methods. For example, css() can only be called before the <head> tag is output. See the comments on the individual methods for details.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Since
Moodle 2.0

Constructor & Destructor Documentation

◆ __construct()

page_requirements_manager::__construct ( )

Page requirements constructor.

Reimplemented in fragment_requirements_manager.

Member Function Documentation

◆ css()

page_requirements_manager::css ( $stylesheet)

Ensure that the specified CSS file is linked to from this page.

Because stylesheet links must go in the <head> part of the HTML, you must call this function before get_head_code() is called. That normally means before the call to print_header. If you call it when it is too late, an exception will be thrown.

Even if a particular style sheet is requested more than once, it will only be linked to once.

Please note use of this feature is strongly discouraged, it is suitable only for places where CSS is submitted directly by teachers. (Students must not be allowed to submit any external CSS because it may contain embedded javascript!). Example of correct use is mod/data.

Parameters
string$stylesheetThe path to the .css file, relative to $CFG->wwwroot. For example: $PAGE->requires->css('mod/data/css.php?d='.$data->id);

◆ css_theme()

page_requirements_manager::css_theme ( moodle_url $stylesheet)

Add theme stylesheet to page - do not use from plugin code, this should be called only from the core renderer!

Parameters
moodle_url$stylesheet
Return values
void

◆ data_for_js()

page_requirements_manager::data_for_js ( $variable,
$data,
$inhead = false )

!!!!!!DEPRECATED!!!!!! please use js_init_call() for everything now.

Make some data from PHP available to JavaScript code.

For example, if you call

     $PAGE->requires->data_for_js('mydata', array('name' => 'Moodle'));

then in JavsScript mydata.name will be 'Moodle'.

Deprecated
Parameters
string$variablethe the name of the JavaScript variable to assign the data to. Will probably work if you use a compound name like 'mybuttons.button[1]', but this should be considered an experimental feature.
mixed$dataThe data to pass to JavaScript. This will be escaped using json_encode, so passing objects and arrays should work.
bool$inheadinitialise in head
Return values
void

◆ event_handler()

page_requirements_manager::event_handler ( $selector,
$event,
$function,
array $arguments = null )

Creates a YUI event handler.

Parameters
mixed$selectorstandard YUI selector for elements, may be array or string, element id is in the form "#idvalue"
string$eventA valid DOM event (click, mousedown, change etc.)
string$functionThe name of the function to call
array$argumentsAn optional array of argument parameters to pass to the function

◆ find_module()

page_requirements_manager::find_module ( $component)
protected

Find out if JS module present and return details.

Parameters
string$componentname of component in frankenstyle, ex: core_group, mod_forum
Return values
arraydescription of module or null if not found

◆ get_amd_footercode()

page_requirements_manager::get_amd_footercode ( )
protected

Returns js code to load amd module loader, then insert inline script tags that contain require() calls using RequireJS.

Return values
string

Reimplemented in fragment_requirements_manager.

◆ get_config_for_javascript()

page_requirements_manager::get_config_for_javascript ( moodle_page $page,
renderer_base $renderer )

Return the safe config values that get set for javascript in "M.cfg".

Since
2.9
Return values
arrayList of safe config values that are available to javascript.

◆ get_css_code()

page_requirements_manager::get_css_code ( )
protected

Returns html tags needed for inclusion of theme CSS.

Return values
string

◆ get_end_code()

page_requirements_manager::get_end_code ( )

Generate any HTML that needs to go at the end of the page.

Normally, this method is called automatically by the code that prints the page footer. You should not normally need to call it in your own code.

Return values
stringthe HTML code to to at the end of the page.

Reimplemented in fragment_requirements_manager.

◆ get_event_handler_code()

page_requirements_manager::get_event_handler_code ( )
protected

Returns code needed for registering of event handlers.

Return values
stringJS code

◆ get_extra_modules_code()

page_requirements_manager::get_extra_modules_code ( )
protected

Adds extra modules specified after printing of page header.

Return values
string

◆ get_head_code()

page_requirements_manager::get_head_code ( moodle_page $page,
core_renderer $renderer )

Generate any HTML that needs to go inside the <head> tag.

Normally, this method is called automatically by the code that prints the <head> tag. You should not normally need to call it in your own code.

Parameters
moodle_page$page
core_renderer$renderer
Return values
stringthe HTML code to to inside the <head> tag.

◆ get_javascript_code()

page_requirements_manager::get_javascript_code ( $ondomready)
protected

Get the inline JavaScript code that need to appear in a particular place.

Parameters
bool$ondomready
Return values
string

◆ get_javascript_init_code()

page_requirements_manager::get_javascript_init_code ( )
protected

Returns js code to be executed when Y is available.

Return values
string

◆ get_jquery_headcode()

page_requirements_manager::get_jquery_headcode ( )
protected

Return jQuery related markup for page start.

Return values
string

◆ get_jsrev()

page_requirements_manager::get_jsrev ( )

Determine the correct JS Revision to use for this load.

Return values
intthe jsrev to use.

◆ get_templaterev()

page_requirements_manager::get_templaterev ( )
protected

Determine the correct Template revision to use for this load.

Return values
intthe templaterev to use.

◆ get_top_of_body_code()

page_requirements_manager::get_top_of_body_code ( renderer_base $renderer)

Generate any HTML that needs to go at the start of the <body> tag.

Normally, this method is called automatically by the code that prints the <head> tag. You should not normally need to call it in your own code.

Parameters
renderer_base$renderer
Return values
stringthe HTML code to go at the start of the <body> tag.

◆ get_yui3lib_headcode()

page_requirements_manager::get_yui3lib_headcode ( )
protected

Returns basic YUI3 JS loading code.

Return values
string

◆ get_yui3lib_headcss()

page_requirements_manager::get_yui3lib_headcss ( )
protected

Returns basic YUI3 CSS code.

Return values
string

◆ has_one_time_item_been_created()

page_requirements_manager::has_one_time_item_been_created ( $thing)

Has a particular bit of HTML that is only required once on this page (e.g.

the contents of the modchooser) already been generated?

Normally, you can use the should_create_one_time_item_now() helper method rather than calling this method directly.

Parameters
string$thingidentifier for the bit of content. Should be of the form frankenstyle_things, e.g. core_course_modchooser.
Return values
boolwhether that bit of output has been created.

◆ init_requirements_data()

page_requirements_manager::init_requirements_data ( moodle_page $page,
core_renderer $renderer )
protected

Initialise with the bits of JavaScript that every Moodle page should have.

Parameters
moodle_page$page
core_renderer$renderer

◆ is_head_done()

page_requirements_manager::is_head_done ( )

Have we already output the code in the <head> tag?

Return values
bool

◆ is_top_of_body_done()

page_requirements_manager::is_top_of_body_done ( )

Have we already output the code at the start of the <body> tag?

Return values
bool

◆ jquery()

page_requirements_manager::jquery ( )

Request inclusion of jQuery library in the page.

NOTE: this should not be used in official Moodle distribution!

◆ jquery_override_plugin()

page_requirements_manager::jquery_override_plugin ( $oldplugin,
$newplugin )

Request replacement of one jQuery plugin by another.

This is useful when themes want to replace the jQuery UI theme, the problem is that theme can not prevent others from including the core ui-css plugin.

Example: 1/ generate new jQuery UI theme and place it into theme/yourtheme/jquery/ 2/ write theme/yourtheme/jquery/plugins.php 3/ init jQuery from theme

// file theme/yourtheme/lib.php function theme_yourtheme_page_init($page) { $page->requires->jquery_plugin('yourtheme-ui-css', 'theme_yourtheme'); $page->requires->jquery_override_plugin('ui-css', 'yourtheme-ui-css'); }

This code prevents loading of standard 'ui-css' which my be requested by other plugins, the 'yourtheme-ui-css' gets loaded only if some other code requires jquery.

Parameters
string$oldpluginoriginal plugin
string$newpluginthe replacement

◆ jquery_plugin()

page_requirements_manager::jquery_plugin ( $plugin,
$component = 'core' )

Request inclusion of jQuery plugin.

NOTE: this should not be used in official Moodle distribution!

jQuery plugins are located in plugin/jquery/* subdirectory, plugin/jquery/plugins.php lists all available plugins.

Included core plugins:

  • jQuery UI

Add-ons may include extra jQuery plugins in jquery/ directory, plugins.php file defines the mapping between plugin names and necessary page includes.

Examples: // file: mod/xxx/view.php $PAGE->requires->jquery(); $PAGE->requires->jquery_plugin('ui'); $PAGE->requires->jquery_plugin('ui-css');

// file: theme/yyy/lib.php function theme_yyy_page_init(moodle_page $page) { $page->requires->jquery(); $page->requires->jquery_plugin('ui'); $page->requires->jquery_plugin('ui-css'); }

// file: blocks/zzz/block_zzz.php public function get_required_javascript() { parent\get_required_javascript(); $this->page->requires->jquery(); $page->requires->jquery_plugin('ui'); $page->requires->jquery_plugin('ui-css'); }

Parameters
string$pluginname of the jQuery plugin as defined in jquery/plugins.php
string$componentname of the component
Return values
boolsuccess

◆ js()

page_requirements_manager::js ( $url,
$inhead = false )

Ensure that the specified JavaScript file is linked to from this page.

NOTE: This function is to be used in RARE CASES ONLY, please store your JS in module.js file and use $PAGE->requires->js_init_call() instead or use /yui/ subdirectories for YUI modules.

By default the link is put at the end of the page, since this gives best page-load performance.

Even if a particular script is requested more than once, it will only be linked to once.

Parameters
string | moodle_url$urlThe path to the .js file, relative to $CFG->dirroot / $CFG->wwwroot. For example '/mod/mymod/customscripts.js'; use moodle_url for external scripts
bool$inheadinitialise in head

◆ js_amd_inline()

page_requirements_manager::js_amd_inline ( $code)

This function appends a block of code to the AMD specific javascript block executed in the page footer, just after loading the requirejs library.

The code passed here can rely on AMD module loading, e.g. require('jquery', function($) {...});

Parameters
string$codeThe JS code to append.

◆ js_call_amd()

page_requirements_manager::js_call_amd ( $fullmodule,
$func = null,
$params = array() )

Load an AMD module and eventually call its method.

This function creates a minimal inline JS snippet that requires an AMD module and eventually calls a single function from the module with given arguments. If it is called multiple times, it will be create multiple snippets.

Parameters
string$fullmoduleThe name of the AMD module to load, formatted as <component name>/<module name>.
string$funcOptional function from the module to call, defaults to just loading the AMD module.
array$paramsThe params to pass to the function (will be serialized into JSON).

◆ js_fix_url()

page_requirements_manager::js_fix_url ( $url)
protected

Returns the actual url through which a JavaScript file is served.

Parameters
moodle_url | string$urlfull moodle url, or shortened path to script.
Exceptions
coding_exceptionif the given $url isn't a shortened url starting with / or a moodle_url instance.
Return values
moodle_url

◆ js_function_call()

page_requirements_manager::js_function_call ( $function,
array $arguments = null,
$ondomready = false,
$delay = 0 )

!!!DEPRECATED!!! please use js_init_call() if possible Ensure that the specified JavaScript function is called from an inline script somewhere on this page.

By default the call will be put in a script tag at the end of the page after initialising Y instance, since this gives best page-load performance and allows you to use YUI3 library.

If you request that a particular function is called several times, then that is what will happen (unlike linking to a CSS or JS file, where only one link will be output).

The main benefit of the method is the automatic encoding of all function parameters.

Deprecated
Parameters
string$functionthe name of the JavaScritp function to call. Can be a compound name like 'Y.Event.purgeElement'. Can also be used to create and object by using a 'function name' like 'new user_selector'.
array$argumentsand array of arguments to be passed to the function. When generating the function call, this will be escaped using json_encode, so passing objects and arrays should work.
bool$ondomreadyIf tru the function is only called when the dom is ready for manipulation.
int$delayThe delay before the function is called.

◆ js_init_call()

page_requirements_manager::js_init_call ( $function,
array $extraarguments = null,
$ondomready = false,
array $module = null )

Ensure that the specified JavaScript function is called from an inline script from page footer.

Parameters
string$functionthe name of the JavaScritp function to with init code, usually something like 'M.mod_mymodule.init'
array$extraargumentsand array of arguments to be passed to the function. The first argument is always the YUI3 Y instance with all required dependencies already loaded.
bool$ondomreadywait for dom ready (helps with some IE problems when modifying DOM)
array$moduleJS module specification array

◆ js_init_code()

page_requirements_manager::js_init_code ( $jscode,
$ondomready = false,
array $module = null )

Add short static javascript code fragment to page footer.

This is intended primarily for loading of js modules and initialising page layout. Ideally the JS code fragment should be stored in plugin renderer so that themes may override it.

Parameters
string$jscode
bool$ondomreadywait for dom ready (helps with some IE problems when modifying DOM)
array$moduleJS module specification array

◆ js_module()

page_requirements_manager::js_module ( $module)

Append YUI3 module to default YUI3 JS loader.

The structure of module array is described at

Parameters
string | array$modulename of module (details are autodetected), or full module specification as array
Return values
void

◆ js_module_loaded()

page_requirements_manager::js_module_loaded ( $module)
protected

Returns true if the module has already been loaded.

Parameters
string | array$module
Return values
boolTrue if the module has already been loaded

◆ set_one_time_item_created()

page_requirements_manager::set_one_time_item_created ( $thing)

Indicate that a particular bit of HTML that is only required once on this page (e.g.

the contents of the modchooser) has been generated (or is about to be)?

Normally, you can use the should_create_one_time_item_now() helper method rather than calling this method directly.

Parameters
string$thingidentifier for the bit of content. Should be of the form frankenstyle_things, e.g. core_course_modchooser.

◆ set_yuicssmodules()

page_requirements_manager::set_yuicssmodules ( array $modules = array())

Set the CSS Modules to be included from YUI.

Parameters
array$modulesThe list of YUI CSS Modules to include.

◆ should_create_one_time_item_now()

page_requirements_manager::should_create_one_time_item_now ( $thing)

Should we generate a bit of content HTML that is only required once on this page (e.g.

the contents of the modchooser), now? Basically, we call has_one_time_item_been_created(), and if the thing has not already been output, we return true to tell the caller to generate it, and also call set_one_time_item_created() to record the fact that it is about to be generated.

That is, a typical usage pattern (in a renderer method) is:

if (!$this->page->requires->should_create_one_time_item_now($thing)) {
    return '';
}
// Else generate it.
Parameters
string$thingidentifier for the bit of content. Should be of the form frankenstyle_things, e.g. core_course_modchooser.
Return values
boolif true, the caller should generate that bit of output now, otherwise don't.

◆ skip_link_to()

page_requirements_manager::skip_link_to ( $target,
$linktext )

Ensure that a skip link to a given target is printed at the top of the <body>.

You must call this function before get_top_of_body_code(), (if not, an exception will be thrown). That normally means you must call this before the call to print_header.

If you ask for a particular skip link to be printed, it is then your responsibility to ensure that the appropriate tag is printed in the body of the page, so that the skip link goes somewhere.

Even if a particular skip link is requested more than once, only one copy of it will be output.

Parameters
string$targetthe name of anchor this link should go to. For example 'maincontent'.
string$linktextThe text to use for the skip link. Normally get_string('skipto', 'access', ...);

◆ string_for_js()

page_requirements_manager::string_for_js ( $identifier,
$component,
$a = null )

Make a language string available to JavaScript.

All the strings will be available in a M.str object in the global namespace. So, for example, after a call to $PAGE->requires->string_for_js('course', 'moodle'); then the JavaScript variable M.str.moodle.course will be 'Course', or the equivalent in the current language.

The arguments to this function are just like the arguments to get_string except that $component is not optional, and there are some aspects to consider when the string contains {$a} placeholder.

If the string does not contain any {$a} placeholder, you can simply use M.str.component.identifier to obtain it. If you prefer, you can call M.util.get_string(identifier, component) to get the same result.

If you need to use {$a} placeholders, there are two options. Either the placeholder should be substituted in PHP on server side or it should be substituted in Javascript at client side.

To substitute the placeholder at server side, just provide the required value for the placeholder when you require the string. Because each string is only stored once in the JavaScript (based on $identifier and $module) you cannot get the same string with two different values of $a. If you try, an exception will be thrown. Once the placeholder is substituted, you can use M.str or M.util.get_string() as shown above:

// Require the string in PHP and replace the placeholder.
$PAGE->requires->string_for_js('fullnamedisplay', 'moodle', $USER);
// Use the result of the substitution in Javascript.
alert(M.str.moodle.fullnamedisplay);

To substitute the placeholder at client side, use M.util.get_string() function. It implements the same logic as get_string():

// Require the string in PHP but keep {$a} as it is.
$PAGE->requires->string_for_js('fullnamedisplay', 'moodle');
// Provide the values on the fly in Javascript.
user = { firstname : 'Harry', lastname : 'Potter' }
alert(M.util.get_string('fullnamedisplay', 'moodle', user);

If you do need the same string expanded with different $a values in PHP on server side, then the solution is to put them in your own data structure (e.g. and array) that you pass to JavaScript with data_for_js().

Parameters
string$identifierthe desired string.
string$componentthe language file to look in.
mixed$aany extra data to add into the string (optional).

◆ strings_for_js()

page_requirements_manager::strings_for_js ( $identifiers,
$component,
$a = null )

Make an array of language strings available for JS.

This function calls the above function string_for_js() for each requested string in the $identifiers array that is passed to the argument for a single module passed in $module.

$PAGE->requires->strings_for_js(array('one', 'two', 'three'), 'mymod', array('a', null, 3));

// The above is identical to calling:

$PAGE->requires->string_for_js('one', 'mymod', 'a'); $PAGE->requires->string_for_js('two', 'mymod'); $PAGE->requires->string_for_js('three', 'mymod', 3);

Parameters
array$identifiersAn array of desired strings
string$componentThe module to load for
mixed$aThis can either be a single variable that gets passed as extra information for every string or it can be an array of mixed data where the key for the data matches that of the identifier it is meant for.

◆ yui_module()

page_requirements_manager::yui_module ( $modules,
$function,
array $arguments = null,
$galleryversion = null,
$ondomready = false )

Creates a JavaScript function call that requires one or more modules to be loaded.

This function can be used to include all of the standard YUI module types within JavaScript:

  • YUI3 modules [node, event, io]
  • YUI2 modules [yui2-*]
  • Moodle modules [moodle-*]
  • Gallery modules [gallery-*]

Before writing new code that makes extensive use of YUI, you should consider it's replacement AMD/JQuery.

See also
js_call_amd()
Parameters
array | string$modulesOne or more modules
string$functionThe function to call once modules have been loaded
array$argumentsAn array of arguments to pass to the function
string$galleryversionDeprecated: The gallery version to use
bool$ondomready

Member Data Documentation

◆ $onetimeitemsoutput

array page_requirements_manager::$onetimeitemsoutput = array()
protected

trackes the names of bits of HTML that are only required once per page.

See has_one_time_item_been_created(), set_one_time_item_created() and should_create_one_time_item_now().


The documentation for this class was generated from the following file: