class HTMLHelper

Utility class for all HTML drawing classes

Properties

static array $formatOptions Option values related to the generation of HTML output. Recognized options are: fmtDepth, integer. The current indent depth.

Methods

static  mixed
_( string $key)

Class loader method

static  boolean
register( string $key, string $function)

Registers a function to be called with a specific key

static  boolean
unregister( string $key)

Removes a key for a method from registry.

static  boolean
isRegistered( string $key)

Test if the key is registered.

static  string
link( string $url, string $text, array|string $attribs = null)

Write a <a> element

static  string
iframe( string $url, string $name, array|string $attribs = null, string $noFrames = '')

Write a <iframe> element

static  string
image( string $file, string $alt, array|string $attribs = null, boolean $relative = false, integer $returnPath)

Write a <img> element

static  array|string|null
stylesheet( string $file, array $options = array(), array $attribs = array())

Write a <link> element to load a CSS file

static  array|string|null
script( string $file, array $options = array(), array $attribs = array())

Write a <script> element to load a JavaScript file

static  void
setFormatOptions( array $options)

Set format related options.

static  string
date( string $input = 'now', string $format = null, mixed $tz = true, boolean $gregorian = false)

Returns formated date according to a given format and time zone.

static  string
tooltip( string $tooltip, mixed $title = '', string $image = 'tooltip.png', string $text = '', string $href = '', string $alt = 'Tooltip', string $class = 'hasTooltip')

Creates a tooltip with an image as button

static  string
tooltipText( string $title = '', string $content = '', boolean $translate = true, boolean $escape = true)

Converts a double colon separated string or 2 separate strings to a string ready for bootstrap tooltips

static  string
calendar( string $value, string $name, string $id, string $format = '%Y-%m-%d', mixed $attribs = array())

Displays a calendar control field

static  array
addIncludePath( string $path = '')

Add a directory where HTMLHelper should search for helpers. You may either pass a string or an array of directories.

static  string
getJSObject( array $array = array())

Internal method to get a JavaScript object notation string from an array

Details

static mixed _( string $key)

Class loader method

Additional arguments may be supplied and are passed to the sub-class. Additional include paths are also able to be specified for third-party use

Parameters

string $key The name of helper method to load, (prefix).(class).function prefix and class are optional and can be used to load custom html helpers.

Return Value

mixed Result of HTMLHelper::call($function, $args)

Exceptions

InvalidArgumentException

static boolean register( string $key, string $function)

Registers a function to be called with a specific key

Parameters

string $key The name of the key
string $function Function or method

Return Value

boolean True if the function is callable

static boolean unregister( string $key)

Removes a key for a method from registry.

Parameters

string $key The name of the key

Return Value

boolean True if a set key is unset

static boolean isRegistered( string $key)

Test if the key is registered.

Parameters

string $key The name of the key

Return Value

boolean True if the key is registered.

Write a <a> element

Parameters

string $url The relative URL to use for the href attribute
string $text The target attribute to use
array|string $attribs Attributes to be added to the <a> element

Return Value

string

static string iframe( string $url, string $name, array|string $attribs = null, string $noFrames = '')

Write a <iframe> element

Parameters

string $url The relative URL to use for the src attribute.
string $name The target attribute to use.
array|string $attribs Attributes to be added to the <iframe> element
string $noFrames The message to display if the iframe tag is not supported.

Return Value

string

static string image( string $file, string $alt, array|string $attribs = null, boolean $relative = false, integer $returnPath)

Write a <img> element

Parameters

string $file The relative or absolute URL to use for the src attribute.
string $alt The alt text.
array|string $attribs Attributes to be added to the <img> element
boolean $relative Flag if the path to the file is relative to the /media folder (and searches in template).
integer $returnPath Defines the return value for the method: -1: Returns a <img> tag without looking for relative files 0: Returns a <img> tag while searching for relative files 1: Returns the file path to the image while searching for relative files

Return Value

string

static array|string|null stylesheet( string $file, array $options = array(), array $attribs = array())

Write a <link> element to load a CSS file

Parameters

string $file Path to file
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

array|string|null nothing if $returnPath is false, null, path or array of path if specific CSS browser files were detected

See also

Browser

static array|string|null script( string $file, array $options = array(), array $attribs = array())

Write a <script> element to load a JavaScript file

Parameters

string $file Path to file.
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

array|string|null Nothing if $returnPath is false, null, path or array of path if specific JavaScript browser files were detected

See also

HTMLHelper::stylesheet()

static void setFormatOptions( array $options)

Set format related options.

Updates the formatOptions array with all valid values in the passed array.

Parameters

array $options Option key/value pairs.

Return Value

void

See also

HTMLHelper::$formatOptions

static string date( string $input = 'now', string $format = null, mixed $tz = true, boolean $gregorian = false)

Returns formated date according to a given format and time zone.

Parameters

string $input String in a format accepted by date(), defaults to "now".
string $format The date format specification string (see {@link PHP_MANUAL#date}).
mixed $tz Time zone to be used for the date. Special cases: boolean true for user setting, boolean false for server setting.
boolean $gregorian True to use Gregorian calendar.

Return Value

string A date translated by the given format and time zone.

See also

strftime

static string tooltip( string $tooltip, mixed $title = '', string $image = 'tooltip.png', string $text = '', string $href = '', string $alt = 'Tooltip', string $class = 'hasTooltip')

Creates a tooltip with an image as button

Parameters

string $tooltip The tip string.
mixed $title The title of the tooltip or an associative array with keys contained in {'title','image','text','href','alt'} and values corresponding to parameters of the same name.
string $image The image for the tip, if no text is provided.
string $text The text for the tip.
string $href A URL that will be used to create the link.
string $alt The alt attribute for img tag.
string $class CSS class for the tool tip.

Return Value

string

static string tooltipText( string $title = '', string $content = '', boolean $translate = true, boolean $escape = true)

Converts a double colon separated string or 2 separate strings to a string ready for bootstrap tooltips

Parameters

string $title The title of the tooltip (or combined '::' separated string).
string $content The content to tooltip.
boolean $translate If true will pass texts through JText.
boolean $escape If true will pass texts through htmlspecialchars.

Return Value

string The tooltip string

static string calendar( string $value, string $name, string $id, string $format = '%Y-%m-%d', mixed $attribs = array())

Displays a calendar control field

Parameters

string $value The date value
string $name The name of the text field
string $id The id of the text field
string $format The date format
mixed $attribs Additional HTML attributes The array can have the following keys: readonly Sets the readonly parameter for the input tag disabled Sets the disabled parameter for the input tag autofocus Sets the autofocus parameter for the input tag autocomplete Sets the autocomplete parameter for the input tag filter Sets the filter for the input tag

Return Value

string HTML markup for a calendar field

static array addIncludePath( string $path = '')

Add a directory where HTMLHelper should search for helpers. You may either pass a string or an array of directories.

Parameters

string $path A path to search.

Return Value

array An array with directory elements

static string getJSObject( array $array = array())

Internal method to get a JavaScript object notation string from an array

Parameters

array $array The array to convert to JavaScript object notation

Return Value

string JavaScript object notation representation of the array