TYPO3 API  SVNRelease
ResourceViewHelper.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script is part of the TYPO3 project - inspiring people to share!  *
00005  *                                                                        *
00006  * TYPO3 is free software; you can redistribute it and/or modify it under *
00007  * the terms of the GNU General Public License version 2 as published by  *
00008  * the Free Software Foundation.                                          *
00009  *                                                                        *
00010  * This script is distributed in the hope that it will be useful, but     *
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00012  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
00013  * Public License for more details.                                       *
00014  *                                                                        */
00015 
00016 /**
00017  * A view helper for creating URIs to resources.
00018  *
00019  * = Examples =
00020  *
00021  * <code title="Defaults">
00022  * <link href="{f:uri.resource(path:'css/stylesheet.css')}" rel="stylesheet" />
00023  * </code>
00024  * <output>
00025  * <link href="Resources/Packages/MyPackage/stylesheet.css" rel="stylesheet" />
00026  * (depending on current package)
00027  * </output>
00028  *
00029  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00030  */
00031 class Tx_Fluid_ViewHelpers_Uri_ResourceViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
00032 
00033     /**
00034      * Render the URI to the resource. The filename is used from child content.
00035      *
00036      * @param string $path The path and filename of the resource (relative to Public resource directory of the extension).
00037      * @param string $extensionName Target extension name. If not set, the current extension name will be used
00038      * @param boolean $absolute If set, an absolute URI is rendered
00039      * @return string The URI to the resource
00040      * @api
00041      */
00042     public function render($path, $extensionName = NULL, $absolute = FALSE) {
00043         if ($extensionName === NULL) {
00044             $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
00045         }
00046         $uri = 'EXT:' . t3lib_div::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
00047         $uri = t3lib_div::getFileAbsFileName($uri);
00048         $uri = substr($uri, strlen(PATH_site));
00049 
00050         if (TYPO3_MODE === 'BE' && $absolute === FALSE && $uri !== FALSE) {
00051             $uri = '../' . $uri;
00052         }
00053 
00054         if ($absolute === TRUE) {
00055             $uri = $this->controllerContext->getRequest()->getBaseURI() . $uri;
00056         }
00057 
00058         return $uri;
00059     }
00060 }
00061 ?>