Class FOFTemplateUtils

Description

A utility class to load view templates, media files and modules.

  • since: 1.0

Located in /libraries/fof/template/utils.php (line 17)


	
			
Method Summary
 static void addCSS (string $path)
 static void addJS (string $path, [boolean $defer = false], [boolean $async = false])
 static mixed addLESS (string $path, [string $altPath = null], [boolean $returnPath = false])
 static array getAltPaths (string $path)
 static string loadPosition (string $position, [int $style = -2])
 static string parsePath (string $path, [boolean $localFile = false])
 static string route ([string $route = ''])
 static string sefSort (string $text, string $field, JObject $list)
Methods
static addCSS (line 28)

Add a CSS file to the page generated by the CMS

  • see: FOFTemplateUtils::parsePath
  • access: public
static void addCSS (string $path)
  • string $path: A fancy path definition understood by parsePath
static addJS (line 66)

Add a JS script file to the page generated by the CMS.

There are three combinations of defer and async (see http://www.w3schools.com/tags/att_script_defer.asp): * $defer false, $async true: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing) * $defer true, $async false: The script is executed when the page has finished parsing. * $defer false, $async false. (default) The script is loaded and executed immediately. When it finishes loading the browser continues parsing the rest of the page.

When you are using $defer = true there is no guarantee about the load order of the scripts. Whichever script loads first will be executed first. The order they appear on the page is completely irrelevant.

  • see: FOFTemplateUtils::parsePath
  • access: public
static void addJS (string $path, [boolean $defer = false], [boolean $async = false])
  • string $path: A fancy path definition understood by parsePath
  • boolean $defer: Adds the defer attribute, meaning that your script will only load after the page has finished parsing.
  • boolean $async: Adds the async attribute, meaning that your script will be executed while the resto of the page continues parsing.
static addLESS (line 98)

Compile a LESS file into CSS and add it to the page generated by the CMS.

This method has integrated cache support. The compiled LESS files will be written to the media/lib_fof/compiled directory of your site. If the file cannot be written we will use the $altPath, if specified

  • return: True = successfully included generated CSS, False = the alternate CSS file was used, null = the source file does not exist
  • see: FOFTemplateUtils::parsePath
  • since: 2.0
  • access: public
static mixed addLESS (string $path, [string $altPath = null], [boolean $returnPath = false])
  • string $path: A fancy path definition understood by parsePath pointing to the source LESS file
  • string $altPath: A fancy path definition understood by parsePath pointing to a precompiled CSS file, used when we can't write the generated file to the output directory
  • boolean $returnPath: Return the URL of the generated CSS file but do not include it. If it can't be generated, false is returned and the alt files are not included
static getAltPaths (line 293)

Parse a fancy path definition into a path relative to the site's root.

It returns both the normal and alternative (template media override) path. For example, media://com_foobar/css/test.css is parsed into array( 'normal' => 'media/com_foobar/css/test.css', 'alternate' => 'templates/mytemplate/media/com_foobar/css//test.css' );

The valid protocols are: media:// The media directory or a media override admin:// Path relative to administrator directory (no alternate) site:// Path relative to site's root (no alternate)

  • return: Array of normal and alternate parsed path
  • access: public
static array getAltPaths (string $path)
  • string $path: Fancy path
static loadPosition (line 377)

Returns the contents of a module position

  • return: The contents of the module position
  • access: public
static string loadPosition (string $position, [int $style = -2])
  • string $position: The position name, e.g. "position-1"
  • int $style: Rendering style; please refer to Joomla!'s code for more information
static parsePath (line 240)

Parse a fancy path definition into a path relative to the site's root, respecting template overrides, suitable for inclusion of media files.

For example, media://com_foobar/css/test.css is parsed into media/com_foobar/css/test.css if no override is found, or templates/mytemplate/media/com_foobar/css/test.css if the current template is called mytemplate and there's a media override for it.

The valid protocols are: media:// The media directory or a media override admin:// Path relative to administrator directory (no overrides) site:// Path relative to site's root (no overrides)

  • return: Parsed path
  • access: public
static string parsePath (string $path, [boolean $localFile = false])
  • string $path: Fancy path
  • boolean $localFile: When true, it returns the local path, not the URL
static route (line 440)

Merges the current url with new or changed parameters.

This method merges the route string with the url parameters defined in current url. The parameters defined in current url, but not given in route string, will automatically reused in the resulting url. But only these following parameters will be reused:

option, view, layout, format

Example:

Assuming that current url is: http://fobar.com/index.php?option=com_foo&view=cpanel

  1.  <?php echo FOFTemplateutils::route('view=categories&layout=tree')?>

Result: http://fobar.com/index.php?option=com_foo&view=categories&layout=tree

  • return: The human readable, complete url
  • access: public
static string route ([string $route = ''])
  • string $route: The parameters string
static sefSort (line 215)

Creates a SEF compatible sort header. Standard Joomla function will add a href="#" tag, so with SEF enabled, the browser will follow the fake link instead of processing the onSubmit event; so we need a fix.

  • return: HTML code for sorting
  • access: public
static string sefSort (string $text, string $field, JObject $list)
  • string $text: Header text
  • string $field: Field used for sorting
  • JObject $list: Object holding the direction and the ordering field

Documentation generated on Tue, 19 Nov 2013 15:16:44 +0100 by phpDocumentor 1.4.3