Needs
in package
Provides a system for injecting CSS and Javascript includes into the head of a document even after the head has been outputted.
Also does replacement for the string "SITE/", which gets changed into the Kohana root directory.
Table of Contents
Properties
- $needs : mixed
- $needs_footer : mixed
Methods
- addCssInclude() : void
- Adds a CSS include need.
- addFooterNeed() : void
- Adds a generic <footer> need.
- addGTMdataLayer() : void
- Add data to GTM dataLayers
- addHeadNeed() : void
- Adds a generic <head> need.
- addJavascriptInclude() : void
- Adds a JS include need.
- addMeta() : mixed
- Adds a meta tag (compat wrapper for addMetaName)
- addMetaName() : mixed
- Adds a meta tag for a meta 'name'
- addMetaProperty() : mixed
- Adds a meta tag for a meta 'property'
- addNeed() : mixed
- Adds a generic need.
- addPreload() : void
- Add a preload tag for a resource.
- dynamicNeedsLoader() : string
- Dynamic loader for <needs/> which have been specified in an AJAX call.
- fileGroup() : void
- Loads a specific file group.
- googleMaps() : mixed
- Load the Google Maps JavaScript API, including an api key from the sprout config
- googleMapsAsync() : void
- Load the Google Maps JavaScript API using sprout config key and given callback JS function name
- googlePlaces() : mixed
- Load Google Autocomplete API, including api key from sprout config
- module() : void
- Alias for {@see Needs::fileGroup}
- removeModule() : void
- Removes a module
- renderGTMDataLayers() : string
- Render GTM dataLayers
- replacePathsString() : mixed
- Do the path replacements for a provided string
- replacePlaceholders() : mixed
- Does needs replacement on all of the html
Properties
$needs
private
static mixed
$needs
= array()
$needs_footer
private
static mixed
$needs_footer
= array()
Methods
addCssInclude()
Adds a CSS include need.
public
static addCssInclude(string $url[, array<string|int, mixed> $extra_attrs = null ][, string $key = null ][, string $location = 'head' ]) : void
Parameters
- $url : string
-
The URL of the CSS file to include
- $extra_attrs : array<string|int, mixed> = null
-
Extra attributes to add to the LINK tag
- $key : string = null
-
The key to use for the need to avoid duplication.
- $location : string = 'head'
-
Where to add the need (head or footer)
addFooterNeed()
Adds a generic <footer> need.
public
static addFooterNeed(string $need[, string $key = null ]) : void
If a key is specified, the need is added with that key allowing for updating of the need later.
Parameters
- $need : string
-
The HTML for the need.
- $key : string = null
-
The key to use for the need to avoid duplication.
addGTMdataLayer()
Add data to GTM dataLayers
public
static addGTMdataLayer(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
addHeadNeed()
Adds a generic <head> need.
public
static addHeadNeed(string $need[, string $key = null ]) : void
If a key is specified, the need is added with that key allowing for updating of the need later.
Parameters
- $need : string
-
The HTML for the need.
- $key : string = null
-
The key to use for the need to avoid duplication.
addJavascriptInclude()
Adds a JS include need.
public
static addJavascriptInclude(string $url[, array<string|int, mixed> $extra_attrs = null ][, string $key = null ][, string $location = 'head' ]) : void
Parameters
- $url : string
-
The URL of the CSS file to include
- $extra_attrs : array<string|int, mixed> = null
-
Extra attributes to add to the JAVASCRIPT tag
- $key : string = null
-
The key to use for the need to avoid duplication.
- $location : string = 'head'
-
Where to add the need (head or footer)
addMeta()
Adds a meta tag (compat wrapper for addMetaName)
public
static addMeta(string $name, string $content[, array<string|int, mixed> $extra_attrs = null ]) : mixed
Use addMetaName instead
Parameters
- $name : string
-
The name of the meta element
- $content : string
-
The content of the meta element
- $extra_attrs : array<string|int, mixed> = null
-
Extra attributes to add to the META tag
addMetaName()
Adds a meta tag for a meta 'name'
public
static addMetaName(string $name, string $content[, array<string|int, mixed> $extra_attrs = null ]) : mixed
Parameters
- $name : string
-
The name of the meta element
- $content : string
-
The content of the meta element
- $extra_attrs : array<string|int, mixed> = null
-
Extra attributes to add to the META tag
addMetaProperty()
Adds a meta tag for a meta 'property'
public
static addMetaProperty(string $property, string $content[, array<string|int, mixed> $extra_attrs = null ]) : mixed
Parameters
- $property : string
-
The property of the meta element
- $content : string
-
The content of the meta element
- $extra_attrs : array<string|int, mixed> = null
-
Extra attributes to add to the META tag
addNeed()
Adds a generic need.
public
static addNeed(string $need[, string $key = null ][, string $location = 'head' ]) : mixed
If a key is specified, the need is added with that key allowing for updating of the need later.
Parameters
- $need : string
-
The HTML for the need.
- $key : string = null
-
The key to use for the need to avoid duplication.
- $location : string = 'head'
-
Where to add the need (head or footer)
addPreload()
Add a preload tag for a resource.
public
static addPreload(string $type, string $url) : void
Parameters
- $type : string
-
style|script|image|font|video|...
- $url : string
dynamicNeedsLoader()
Dynamic loader for <needs/> which have been specified in an AJAX call.
public
static dynamicNeedsLoader() : string
NOTE This does not support footer needs.
Returns HTML of a snippet of JavaScript which does dynamic loading of the needs. Calls the function "dynamicNeedsLoader" located in media/js/common.js, which does the actual loading of the JS or CSS file. The dynamic loader will only load files not currently loaded.
This function must be called after all Needs have been specified.
Tags
Return values
string —HTML Snippet of JavaScript
fileGroup()
Loads a specific file group.
public
static fileGroup(string $name[, string $location = 'head' ]) : void
The files in a group are JS and CSS files with matching names, e.g. file.js and file.css The JS files can be minified, so 'file' will match file.min.js; minified files take precedence.
The group can be:
- a straight file basename e.g. 'my_file', or
- sprout plus a file basename, e.g. 'sprout/my_file', or
- a module name plus a file basename, e.g. 'MyModule/my_file'
The files must be in the 'media/(js/css)/' directory beneath the relevant path. As per the following exaples:
If the group name 'fb' is requested, the following two files will be included, if they are found:
- media/css/fb.css
- media/js/fb.min.js OR media/js/fb.js
If 'sprout/admin_layout' is requested, the following two files will be included, if they are found:
- sprout/media/css/admin_layout.css
- sprout/media/js/admin_layout.min.js OR sprout/media/js/admin_layout.js
If 'Users/users' is requested, the following two files will be included, if found:
- modules/Users/media/css/users.css
- modules/Users/media/js/users.min.js OR modules/Users/media/js/users.js
Parameters
- $name : string
-
The name of the file group, e.g. 'Forms/admin_fields'
- $location : string = 'head'
-
Where to add the need (head or footer)
Tags
googleMaps()
Load the Google Maps JavaScript API, including an api key from the sprout config
public
static googleMaps() : mixed
Always loaded in the head
googleMapsAsync()
Load the Google Maps JavaScript API using sprout config key and given callback JS function name
public
static googleMapsAsync(string $callback) : void
Parameters
- $callback : string
-
Javascript function name
googlePlaces()
Load Google Autocomplete API, including api key from sprout config
public
static googlePlaces() : mixed
module()
Alias for {@see Needs::fileGroup}
public
static module(string $name[, string $location = 'head' ]) : void
Since the nomenclature makes no sense
Parameters
- $name : string
- $location : string = 'head'
-
Where to add the need (head or footer)
removeModule()
Removes a module
public
static removeModule(string $key) : void
e.g. Needs::fileGroup('facebox') can be removed with Needs::removeModule('facebox')
Parameters
- $key : string
-
The key to use for the need to avoid duplication.
renderGTMDataLayers()
Render GTM dataLayers
public
static renderGTMDataLayers() : string
Return values
string —HTML
replacePathsString()
Do the path replacements for a provided string
public
static replacePathsString(mixed $str) : mixed
TODO this doesn't belong here.
Parameters
- $str : mixed
replacePlaceholders()
Does needs replacement on all of the html
public
static replacePlaceholders(DisplayEvent $event) : mixed
Parameters
- $event : DisplayEvent