TYPO3 API  SVNRelease
SectionViewHelper.php
Go to the documentation of this file.
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  * A Section view helper
00025  *
00026  * == Examples ==
00027  *
00028  * <code title="Rendering sections">
00029  * <f:section name="someSection">This is a section. {foo}</f:section>
00030  * <f:render section="someSection" arguments="{foo: someVariable}" />
00031  * </code>
00032  * <output>
00033  * the content of the section "someSection". The content of the variable {someVariable} will be available in the partial as {foo}
00034  * </output>
00035  *
00036  * <code title="Rendering recursive sections">
00037  * <f:section name="mySection">
00038  *  <ul>
00039  *    <f:for each="{myMenu}" as="menuItem">
00040  *      <li>
00041  *        {menuItem.text}
00042  *        <f:if condition="{menuItem.subItems}">
00043  *          <f:render section="mySection" arguments="{myMenu: menuItem.subItems}" />
00044  *        </f:if>
00045  *      </li>
00046  *    </f:for>
00047  *  </ul>
00048  * </f:section>
00049  * <f:render section="mySection" arguments="{myMenu: menu}" />
00050  * </code>
00051  * <output>
00052  * <ul>
00053  *   <li>menu1
00054  *     <ul>
00055  *       <li>menu1a</li>
00056  *       <li>menu1b</li>
00057  *     </ul>
00058  *   </li>
00059  * [...]
00060  * (depending on the value of {menu})
00061  * </output>
00062  *
00063  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00064  * @api
00065  */
00066 class Tx_Fluid_ViewHelpers_SectionViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper implements Tx_Fluid_Core_ViewHelper_Facets_PostParseInterface {
00067 
00068     /**
00069      * Initialize the arguments.
00070      *
00071      * @return void
00072      * @author Sebastian Kurfürst <sebastian@typo3.org>
00073      * @api
00074      */
00075     public function initializeArguments() {
00076         $this->registerArgument('name', 'string', 'Name of the section', TRUE);
00077     }
00078 
00079     /**
00080      * Save the associated view helper node in a static public class variable.
00081      * called directly after the view helper was built.
00082      *
00083      * @param Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode $syntaxTreeNode
00084      * @param array $viewHelperArguments
00085      * @param Tx_Fluid_Core_ViewHelper_TemplateVariableContainer $variableContainer
00086      * @return void
00087      * @author Sebastian Kurfürst <sebastian@typo3.org>
00088      */
00089     static public function postParseEvent(Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode $syntaxTreeNode, array $viewHelperArguments, Tx_Fluid_Core_ViewHelper_TemplateVariableContainer $variableContainer) {
00090         $sectionName = $viewHelperArguments['name']->getText();
00091         if (!$variableContainer->exists('sections')) {
00092             $variableContainer->add('sections', array());
00093         }
00094         $sections = $variableContainer->get('sections');
00095         $sections[$sectionName] = $syntaxTreeNode;
00096         $variableContainer->remove('sections');
00097         $variableContainer->add('sections', $sections);
00098     }
00099 
00100     /**
00101      * Rendering directly returns all child nodes.
00102      *
00103      * @return string HTML String of all child nodes.
00104      * @author Sebastian Kurfürst <sebastian@typo3.org>
00105      * @api
00106      */
00107     public function render() {
00108         if ($this->viewHelperVariableContainer->exists('Tx_Fluid_ViewHelpers_SectionViewHelper', 'isCurrentlyRenderingSection')) {
00109             $this->viewHelperVariableContainer->remove('Tx_Fluid_ViewHelpers_SectionViewHelper', 'isCurrentlyRenderingSection');
00110             return $this->renderChildren();
00111         }
00112         return '';
00113     }
00114 }
00115 
00116 ?>