|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* * 00004 * This script belongs to the FLOW3 package "Fluid". * 00005 * * 00006 * It is free software; you can redistribute it and/or modify it under * 00007 * the terms of the GNU Lesser General Public License as published by the * 00008 * Free Software Foundation, either version 3 of the License, or (at your * 00009 * option) any later version. * 00010 * * 00011 * This script is distributed in the hope that it will be useful, but * 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * 00013 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the script. * 00018 * If not, see http://www.gnu.org/licenses/lgpl.html * 00019 * * 00020 * The TYPO3 project - inspiring people to share! * 00021 * */ 00022 00023 /** 00024 * ViewHelper that renders a section or a specified partial 00025 * 00026 * == Examples == 00027 * 00028 * <code title="Rendering partials"> 00029 * <f:render partial="SomePartial" arguments="{foo: someVariable}" /> 00030 * </code> 00031 * <output> 00032 * the content of the partial "SomePartial". The content of the variable {someVariable} will be available in the partial as {foo} 00033 * </output> 00034 * 00035 * <code title="Rendering sections"> 00036 * <f:section name="someSection">This is a section. {foo}</f:section> 00037 * <f:render section="someSection" arguments="{foo: someVariable}" /> 00038 * </code> 00039 * <output> 00040 * the content of the section "someSection". The content of the variable {someVariable} will be available in the partial as {foo} 00041 * </output> 00042 * 00043 * <code title="Rendering recursive sections"> 00044 * <f:section name="mySection"> 00045 * <ul> 00046 * <f:for each="{myMenu}" as="menuItem"> 00047 * <li> 00048 * {menuItem.text} 00049 * <f:if condition="{menuItem.subItems}"> 00050 * <f:render section="mySection" arguments="{myMenu: menuItem.subItems}" /> 00051 * </f:if> 00052 * </li> 00053 * </f:for> 00054 * </ul> 00055 * </f:section> 00056 * <f:render section="mySection" arguments="{myMenu: menu}" /> 00057 * </code> 00058 * <output> 00059 * <ul> 00060 * <li>menu1 00061 * <ul> 00062 * <li>menu1a</li> 00063 * <li>menu1b</li> 00064 * </ul> 00065 * </li> 00066 * [...] 00067 * (depending on the value of {menu}) 00068 * </output> 00069 * 00070 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00071 * @api 00072 */ 00073 class Tx_Fluid_ViewHelpers_RenderViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper { 00074 00075 /** 00076 * Renders the content. 00077 * 00078 * @param string $section Name of section to render. If used in a layout, renders a section of the main content file. If used inside a standard template, renders a section of the same file. 00079 * @param string $partial Reference to a partial. 00080 * @param array $arguments Arguments to pass to the partial. 00081 * @return string 00082 * @author Sebastian Kurfürst <sebastian@typo3.org> 00083 * @api 00084 */ 00085 public function render($section = NULL, $partial = NULL, $arguments = array()) { 00086 $arguments = $this->loadSettingsIntoArguments($arguments); 00087 00088 if ($partial !== NULL) { 00089 return $this->viewHelperVariableContainer->getView()->renderPartial($partial, $section, $arguments); 00090 } elseif ($section !== NULL) { 00091 return $this->viewHelperVariableContainer->getView()->renderSection($section, $arguments); 00092 } 00093 return ''; 00094 } 00095 00096 /** 00097 * If $arguments['settings'] is not set, it is loaded from the TemplateVariableContainer (if it is available there). 00098 * 00099 * @param array $arguments 00100 * @return array 00101 */ 00102 protected function loadSettingsIntoArguments($arguments) { 00103 if (!isset($arguments['settings']) && $this->templateVariableContainer->exists('settings')) { 00104 $arguments['settings'] = $this->templateVariableContainer->get('settings'); 00105 } 00106 return $arguments; 00107 } 00108 } 00109 00110 ?>
1.8.0