class HtmlDocument extends Document

HtmlDocument class, provides an easy interface to parse and display a HTML document

Properties

string $title Document title from Document
string $description Document description from Document
Document full URL from Document
string $base Document base URL from Document
string $language Contains the document language setting from Document
string $direction Contains the document direction setting from Document
string $_generator Document generator from Document
string|Date $_mdate Document modified date from Document
string $_tab Tab string from Document
string $_lineEnd Contains the line end string from Document
string $_charset Contains the character encoding string from Document
string $_mime Document mime type from Document
string $_namespace Document namespace from Document
string $_profile Document profile from Document
array $_scripts Array of linked scripts from Document
array $_script Array of scripts placed in the header from Document
array $_styleSheets Array of linked style sheets from Document
array $_style Array of included style declarations from Document
array $_metaTags Array of meta tags from Document
object $_engine The rendering engine from Document
string $_type The document type from Document
static mixed $_buffer Array of buffered output from Document
Array of Header <link> tags
array $_custom Array of custom tags
string $template Name of the template
string $baseurl Base url
array $params Array of template parameters
array $_file File name

Methods

__construct( array $options = array())

Class constructor

static  object
getInstance( string $type = 'html', array $attributes = array())

Returns the global Document object, only creating it if it doesn't already exist.

from Document
setType( string $type)

Set the document type

from Document
string
getType()

Returns the document type

from Document
mixed
getBuffer( string $type = null, string $name = null, array $attribs = array())

Get the contents of a document include

setBuffer( string $content, array $options = array())

Set the contents a document includes

string
getMetaData( string $name, string $attribute = 'name')

Gets a meta tag.

from Document
setMetaData( string $name, mixed $content, string $attribute = 'name')

Sets or alters a meta tag.

from Document
addScript( string $url, array $options = array(), array $attribs = array())

Adds a linked script to the page

from Document
addScriptVersion( string $url, array $options = array(), array $attribs = array())

Adds a linked script to the page with a version to allow to flush it. Ex: myscript.js?54771616b5bceae9df03c6173babf11d If not specified Joomla! automatically handles versioning

from Document
addScriptDeclaration( string $content, string $type = 'text/javascript')

Adds a script to the page

from Document
addScriptOptions( string $key, mixed $options, bool $merge = true)

Add option for script

from Document
array
getScriptOptions( string $key = null)

Get script(s) options

from Document
addStyleSheet( string $url, array $options = array(), array $attribs = array())

Adds a linked stylesheet to the page

from Document
addStyleSheetVersion( string $url, array $options = array(), array $attribs = array())

Adds a linked stylesheet version to the page. Ex: template.css?54771616b5bceae9df03c6173babf11d If not specified Joomla! automatically handles versioning

from Document
addStyleDeclaration( string $content, string $type = 'text/css')

Adds a stylesheet declaration to the page

from Document
setCharset( string $type = 'utf-8')

Sets the document charset

from Document
string
getCharset()

Returns the document charset encoding.

from Document
setLanguage( string $lang = 'en-gb')

Sets the global document language declaration. Default is English (en-gb).

from Document
string
getLanguage()

Returns the document language.

from Document
setDirection( string $dir = 'ltr')

Sets the global document direction declaration. Default is left-to-right (ltr).

from Document
string
getDirection()

Returns the document direction declaration.

from Document
setTitle( string $title)

Sets the title of the document

from Document
string
getTitle()

Return the title of the document.

from Document
setMediaVersion( string $mediaVersion)

Set the assets version

from Document
string
getMediaVersion()

Return the media version

from Document
setBase( string $base)

Sets the base URI of the document

from Document
string
getBase()

Return the base URI of the document.

from Document
setDescription( string $description)

Sets the description of the document

from Document
string
getDescription()

Return the description of the document.

from Document
setLink( string $url)

Sets the document link

from Document
string
getLink()

Returns the document base url

from Document
setGenerator( string $generator)

Sets the document generator

from Document
string
getGenerator()

Returns the document generator

from Document
setModifiedDate( string|Date $date)

Sets the document modified date

from Document
string|Date
getModifiedDate()

Returns the document modified date

from Document
setMimeEncoding( string $type = 'text/html', boolean $sync = true)

Sets the document MIME encoding that is sent to the browser.

from Document
string
getMimeEncoding()

Return the document MIME encoding that is sent to the browser.

from Document
setLineEnd( string $style)

Sets the line end style to Windows, Mac, Unix or a custom string.

from Document
string
_getLineEnd()

Returns the lineEnd

from Document
setTab( string $string)

Sets the string used to indent HTML

from Document
string
_getTab()

Returns a string containing the unit for indenting HTML

from Document
loadRenderer( string $type)

Load a renderer

from Document
parse( array $params = array())

Parses the template and populates the buffer

void
render( boolean $caching = false, array $params = array())

Outputs the template to the browser.

array
getHeadData()

Get the HTML document head data

resetHeadData( mixed $types = null)

Reset the HTML document head data

setHeadData( array $data)

Set the HTML document head data

mergeHeadData( array $data)

Merge the HTML document head data

addHeadLink( string $href, string $relation, string $relType = 'rel', array $attribs = array())

Adds <link> tags to the head of the document

addFavicon( string $href, string $type = 'image/vnd.microsoft.icon', string $relation = 'shortcut icon')

Adds a shortcut icon (favicon)

addCustomTag( string $html)

Adds a custom HTML string to the head block

boolean
isHtml5()

Returns whether the document is set up to be output as HTML5

void
setHtml5( bool $state)

Sets whether the document should be output as HTML5

integer
countModules( string $condition)

Count the modules based on the given condition

integer
countMenuChildren()

Count the number of child menu items of the current active menu item

Details

__construct( array $options = array())

Class constructor

Parameters

array $options Associative array of options

static object getInstance( string $type = 'html', array $attributes = array())

Returns the global Document object, only creating it if it doesn't already exist.

Parameters

string $type The document type to instantiate
array $attributes Array of attributes

Return Value

object The document object.

Document setType( string $type)

Set the document type

Parameters

string $type Type document is to set to

Return Value

Document instance of $this to allow chaining

string getType()

Returns the document type

Return Value

string

mixed getBuffer( string $type = null, string $name = null, array $attribs = array())

Get the contents of a document include

Parameters

string $type The type of renderer
string $name The name of the element to render
array $attribs Associative array of remaining attributes.

Return Value

mixed

Document setBuffer( string $content, array $options = array())

Set the contents a document includes

Parameters

string $content The content to be set in the buffer.
array $options Array of optional elements.

Return Value

Document instance of $this to allow chaining

string getMetaData( string $name, string $attribute = 'name')

Gets a meta tag.

Parameters

string $name Name of the meta HTML tag
string $attribute Attribute to use in the meta HTML tag

Return Value

string

Document setMetaData( string $name, mixed $content, string $attribute = 'name')

Sets or alters a meta tag.

Parameters

string $name Name of the meta HTML tag
mixed $content Value of the meta HTML tag as array or string
string $attribute Attribute to use in the meta HTML tag

Return Value

Document instance of $this to allow chaining

Document addScript( string $url, array $options = array(), array $attribs = array())

Adds a linked script to the page

Parameters

string $url URL to the linked script.
array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
array $attribs Array of attributes. Example: array('id' => 'scriptid', 'async' => 'async', 'data-test' => 1)

Return Value

Document instance of $this to allow chaining

Document addScriptVersion( string $url, array $options = array(), array $attribs = array())

Adds a linked script to the page with a version to allow to flush it. Ex: myscript.js?54771616b5bceae9df03c6173babf11d If not specified Joomla! automatically handles versioning

Parameters

string $url URL to the linked script.
array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
array $attribs Array of attributes. Example: array('id' => 'scriptid', 'async' => 'async', 'data-test' => 1)

Return Value

Document instance of $this to allow chaining

Document addScriptDeclaration( string $content, string $type = 'text/javascript')

Adds a script to the page

Parameters

string $content Script
string $type Scripting mime (defaults to 'text/javascript')

Return Value

Document instance of $this to allow chaining

Document addScriptOptions( string $key, mixed $options, bool $merge = true)

Add option for script

Parameters

string $key Name in Storage
mixed $options Scrip options as array or string
bool $merge Whether merge with existing (true) or replace (false)

Return Value

Document instance of $this to allow chaining

array getScriptOptions( string $key = null)

Get script(s) options

Parameters

string $key Name in Storage

Return Value

array Options for given $key, or all script options

Document addStyleSheet( string $url, array $options = array(), array $attribs = array())

Adds a linked stylesheet to the page

Parameters

string $url URL to the linked style sheet
array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
array $attribs Array of attributes. Example: array('id' => 'stylesheet', 'data-test' => 1)

Return Value

Document instance of $this to allow chaining

Document addStyleSheetVersion( string $url, array $options = array(), array $attribs = array())

Adds a linked stylesheet version to the page. Ex: template.css?54771616b5bceae9df03c6173babf11d If not specified Joomla! automatically handles versioning

Parameters

string $url URL to the linked style sheet
array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
array $attribs Array of attributes. Example: array('id' => 'stylesheet', 'data-test' => 1)

Return Value

Document instance of $this to allow chaining

Document addStyleDeclaration( string $content, string $type = 'text/css')

Adds a stylesheet declaration to the page

Parameters

string $content Style declarations
string $type Type of stylesheet (defaults to 'text/css')

Return Value

Document instance of $this to allow chaining

Document setCharset( string $type = 'utf-8')

Sets the document charset

Parameters

string $type Charset encoding string

Return Value

Document instance of $this to allow chaining

string getCharset()

Returns the document charset encoding.

Return Value

string

Document setLanguage( string $lang = 'en-gb')

Sets the global document language declaration. Default is English (en-gb).

Parameters

string $lang The language to be set

Return Value

Document instance of $this to allow chaining

string getLanguage()

Returns the document language.

Return Value

string

Document setDirection( string $dir = 'ltr')

Sets the global document direction declaration. Default is left-to-right (ltr).

Parameters

string $dir The language direction to be set

Return Value

Document instance of $this to allow chaining

string getDirection()

Returns the document direction declaration.

Return Value

string

Document setTitle( string $title)

Sets the title of the document

Parameters

string $title The title to be set

Return Value

Document instance of $this to allow chaining

string getTitle()

Return the title of the document.

Return Value

string

Document setMediaVersion( string $mediaVersion)

Set the assets version

Parameters

string $mediaVersion Media version to use

Return Value

Document instance of $this to allow chaining

string getMediaVersion()

Return the media version

Return Value

string

Document setBase( string $base)

Sets the base URI of the document

Parameters

string $base The base URI to be set

Return Value

Document instance of $this to allow chaining

string getBase()

Return the base URI of the document.

Return Value

string

Document setDescription( string $description)

Sets the description of the document

Parameters

string $description The description to set

Return Value

Document instance of $this to allow chaining

string getDescription()

Return the description of the document.

Return Value

string

Sets the document link

Parameters

string $url A url

Return Value

Document instance of $this to allow chaining

Returns the document base url

Return Value

string

Document setGenerator( string $generator)

Sets the document generator

Parameters

string $generator The generator to be set

Return Value

Document instance of $this to allow chaining

string getGenerator()

Returns the document generator

Return Value

string

Document setModifiedDate( string|Date $date)

Sets the document modified date

Parameters

string|Date $date The date to be set

Return Value

Document instance of $this to allow chaining

Exceptions

InvalidArgumentException

string|Date getModifiedDate()

Returns the document modified date

Return Value

string|Date

Document setMimeEncoding( string $type = 'text/html', boolean $sync = true)

Sets the document MIME encoding that is sent to the browser.

This usually will be text/html because most browsers cannot yet accept the proper mime settings for XHTML: application/xhtml+xml and to a lesser extent application/xml and text/xml. See the W3C note ({@link http://www.w3.org/TR/xhtml-media-types/ http://www.w3.org/TR/xhtml-media-types/}) for more details.

Parameters

string $type The document type to be sent
boolean $sync Should the type be synced with HTML?

Return Value

Document instance of $this to allow chaining

string getMimeEncoding()

Return the document MIME encoding that is sent to the browser.

Return Value

string

Document setLineEnd( string $style)

Sets the line end style to Windows, Mac, Unix or a custom string.

Parameters

string $style "win", "mac", "unix" or custom string.

Return Value

Document instance of $this to allow chaining

string _getLineEnd()

Returns the lineEnd

Return Value

string

Document setTab( string $string)

Sets the string used to indent HTML

Parameters

string $string String used to indent ("\11", "\t", ' ', etc.).

Return Value

Document instance of $this to allow chaining

string _getTab()

Returns a string containing the unit for indenting HTML

Return Value

string

DocumentRenderer loadRenderer( string $type)

Load a renderer

Parameters

string $type The renderer type

Return Value

DocumentRenderer

Exceptions

RuntimeException

Document parse( array $params = array())

Parses the template and populates the buffer

Parameters

array $params The array of parameters

Return Value

Document instance of $this to allow chaining

void render( boolean $caching = false, array $params = array())

Outputs the template to the browser.

Parameters

boolean $caching If true, cache the output
array $params Associative array of attributes

Return Value

void The rendered data

array getHeadData()

Get the HTML document head data

Return Value

array The document head data in array form

HtmlDocument resetHeadData( mixed $types = null)

Reset the HTML document head data

Parameters

mixed $types type or types of the heads elements to reset

Return Value

HtmlDocument instance of $this to allow chaining

HtmlDocument|null setHeadData( array $data)

Set the HTML document head data

Parameters

array $data The document head data in array form

Return Value

HtmlDocument|null instance of $this to allow chaining or null for empty input data

HtmlDocument|null mergeHeadData( array $data)

Merge the HTML document head data

Parameters

array $data The document head data in array form

Return Value

HtmlDocument|null instance of $this to allow chaining or null for empty input data

Adds <link> tags to the head of the document

$relType defaults to 'rel' as it is the most common relation type used. ('rev' refers to reverse relation, 'rel' indicates normal, forward relation.) Typical tag: <link href="index.php" rel="Start">

Parameters

string $href The link that is being related.
string $relation Relation of link.
string $relType Relation type attribute. Either rel or rev (default: 'rel').
array $attribs Associative array of remaining attributes.

Return Value

HtmlDocument instance of $this to allow chaining

HtmlDocument addFavicon( string $href, string $type = 'image/vnd.microsoft.icon', string $relation = 'shortcut icon')

Adds a shortcut icon (favicon)

This adds a link to the icon shown in the favorites list or on the left of the url in the address bar. Some browsers display it on the tab, as well.

Parameters

string $href The link that is being related.
string $type File type
string $relation Relation of link

Return Value

HtmlDocument instance of $this to allow chaining

HtmlDocument addCustomTag( string $html)

Adds a custom HTML string to the head block

Parameters

string $html The HTML to add to the head

Return Value

HtmlDocument instance of $this to allow chaining

boolean isHtml5()

Returns whether the document is set up to be output as HTML5

Return Value

boolean true when HTML5 is used

void setHtml5( bool $state)

Sets whether the document should be output as HTML5

Parameters

bool $state True when HTML5 should be output

Return Value

void

integer countModules( string $condition)

Count the modules based on the given condition

Parameters

string $condition The condition to use

Return Value

integer Number of modules found

integer countMenuChildren()

Count the number of child menu items of the current active menu item

Return Value

integer Number of child menu items