Access Keys:
Skip to content (Access Key - 0)
Home (Access Key - 1)
All spaces... (Access Key - 3)
Log in (Access Key - 5)
Sign up (Access Key - 6)
Development

Mambo Manual is part of the documentation project for the Mambo open source content management system

Toggle Sidebar

Class mosHtmlHelper


Note: this class is currently under development and subject to change.

Class Notes

Class mosHtmlHelper started life as a way to control the document DTD and as a replacement for mosShowHead but it evolved into much more. It also contains methods for outputting common html head tags. Or it can be used to output a head tag with Mambo core data automatically inserted. mosHtmlHelper was built around a static singleton accessor object so it can be used either as an object or as a singleton.

Warning: Under the current release, the singleton should NOT be used in the back end. It should be possible to create a new object using $myhelper = new mosHtmlHelperand then use some of the rendering methods to create custom tags. However, the class has not been tested for use in this manner.

Notes:

  1. The class uses a singleton accessor.
  2. All funtions use a pointer to a static singleton object.
  3. Any function call initializes the singleton object if not already set.
  4. There is no constructor.

    Usage

As an object$html =& mosHtmlHelper::getInstance();$html->someFunction();As a singletonmosHtmlHelper::someFunction();

Properties

var $_tags

An associative array of available html tags. The tags are setup to be used with sprintf() or vsprintf(). Each tag has a number of %s variables placed in strategic locations. These variables allow you to create consistent valid html. For more information see Class mosHtmlHelper code#tags

var $_docTypes

An associative array of document type definitions (DTD). A DTD is retrieved or rendered using the array key. The key is also used in the backend configuration for creating the drop-down list when editing mosConfig_doctype. For more information see Class mosHtmlHelper code#doctypes

var $_docTypesMobile

An array of Mobile document types used to test document type. If the helper object document type matches one of these array items, the xml prologue is automatically rendered. Mobile document types are not available for selection in the back end when editing the site document type. For more information see Class mosHtmlHelper code#mobile

var $_headTags

An array to contain head tags created by the mainframe class. The array is loaded when the singleton object is initialized.

var $doctype

Stores the array key from $docTypes. Used to set the DTD. Retrieved from mosConfig_doctype during initialization. Defaults to _xml-trans.

var $charset

Stores the language character set. Used in the DTD and the character set meta tag. Retrieved from the core language object during initialization Defaults to utf-8.

var $useXmlPrologue

Stores a flag that turns xml prologue on and off. Defaults to false.

for additional information on class properties, see Class mosHtmlHelper code#prop

Methods

The standard class methods include setters and getters. They also include methods for rendering a tag, setting the document type, turning the xml prologue on and off, and a flexible replacement for mosShowHead().

There are two types of tag rendering functions. One is a common render() function. The other is a function specific to a particular tag such as renderCss(). The first type, render(), renders the tag and inserts default variables from the Mambo core. The second type, renderSomeTag(), allows the developer to pass custom variables to the tag.

For a comprehensive list of functions see Class mosHtmlHelper methods

Examples

Note: the following examples use singleton methods. But they could also be used as an object. Either method would work equally well. $html->render('doctype') and mosHtmlHelper::render('doctype') perform the same function.

mosHtmlHelper::render('doctype') - renders a DTD based on mosConfig_doctype. If mosConfig_doctype is not set (after an upgrade), it defaults to XHTML 1.0 Transitional.

mosHtmlHelper::renderDoctype() - same as mosHtmlHelper::render('doctype').

mosHtmlHelper::renderDoctype($doctype) - same as mosHtmlHelper::render('doctype') but renders a DTD based on $doctype. The $doctype variable should be an array key from property $_docTypes.

mosHtmlHelper::render('xmlprologue') - Renders a valid xml prologue ONLY if $useXmlPrologue is true OR $doctype matches one of the array values in $_docTypesMobile.

mosHtmlHelper::renderXmlPrologue() - same as mosHtmlHelper::render('xmlprologue').

mosHtmlHelper::renderXmlPrologue($charset) - same as mosHtmlHelper::render('xmlprologue') but uses the character set defined in a variable named $charset. Note - there is no error checking for $charset. Whatever is passed to the function is rendered in the xml prologue.

mosHtmlHelper::renderXmlPrologue(", true) - same as mosHtmlHelper::render('xmlprologue') but forces the rendering of the xml prologue.

mosHtmlHelper::renderXmlPrologue($charset, true) - always renders the xml prologue and uses the character set defined in a variable named $charset.

mosHtmlHelper::render('css') - renders a standard css link tag using a default of /templates/some_template/css/template_css.css. If a 'print.css' file exists in the /css/ folder, it is also rendered with 'media="print"'

mosHtmlHelper::renderCss() - same as mosHtmlHelper::render('css').

mosHtmlHelper::renderCss('a/path/to/my.css') - renders a css link tag and inserts a path to the css file.

mosHtmlHelper::renderCss('a/path/to/my.css', 'screen') - renders a css link tag, inserts a path to the css file, and inserts a media type.

mosHtmlHelper::renderJavascript('a/path/to/my.js') - renders a javascript script tag and inserts a path to the javascript file.

mosHtmlHelper::renderJavascript(", $code) - renders a javascript script tag and inserts a block of javascript code stored in $code.

Files

Definition

/includes/core.helpers.php

Dependencies

/includes/core.classes.php

Toggle Sidebar
Space Navigation
Added by Lynne Pope on 28 Dec, 2007 10:24, last edited by Lynne Pope on 28 Dec, 2007 10:56

Adaptavist Theme Builder Powered by Atlassian Confluence
Free theme builder license