[!!!][+FEATURE\1d] Add a reserved variable {_all} returning all template variables
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / RenderViewHelper.php
index df8b4d2..c2c7dfd 100644 (file)
  *                                                                        */
 
 /**
+ * ViewHelper that renders a section or a specified partial
+ *
+ * == Examples ==
+ *
+ * <code title="Rendering partials">
+ * <f:render partial="SomePartial" arguments="{foo: someVariable}" />
+ * </code>
+ * <output>
+ * the content of the partial "SomePartial". The content of the variable {someVariable} will be available in the partial as {foo}
+ * </output>
+ *
+ * <code title="Rendering sections">
+ * <f:section name="someSection">This is a section. {foo}</f:section>
+ * <f:render section="someSection" arguments="{foo: someVariable}" />
+ * </code>
+ * <output>
+ * the content of the section "someSection". The content of the variable {someVariable} will be available in the partial as {foo}
+ * </output>
+ *
+ * <code title="Rendering recursive sections">
+ * <f:section name="mySection">
+ *  <ul>
+ *    <f:for each="{myMenu}" as="menuItem">
+ *      <li>
+ *        {menuItem.text}
+ *        <f:if condition="{menuItem.subItems}">
+ *          <f:render section="mySection" arguments="{myMenu: menuItem.subItems}" />
+ *        </f:if>
+ *      </li>
+ *    </f:for>
+ *  </ul>
+ * </f:section>
+ * <f:render section="mySection" arguments="{myMenu: menu}" />
+ * </code>
+ * <output>
+ * <ul>
+ *   <li>menu1
+ *     <ul>
+ *       <li>menu1a</li>
+ *       <li>menu1b</li>
+ *     </ul>
+ *   </li>
+ * [...]
+ * (depending on the value of {menu})
+ * </output>
+ *
+ *
+ * <code title="Passing all variables to a partial">
+ * <f:render partial="somePartial" arguments="{_all}" />
+ * </code>
+ * <output>
+ * the content of the partial "somePartial".
+ * Using the reserved keyword "_all", all available variables will be passed along to the partial
+ * </output>
  *
- * @version $Id: RenderViewHelper.php 3346 2009-10-22 17:26:10Z k-fish $
- * @package Fluid
- * @subpackage ViewHelpers
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  * @api
- * @scope prototype
  */
 class Tx_Fluid_ViewHelpers_RenderViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
 
@@ -41,17 +91,29 @@ class Tx_Fluid_ViewHelpers_RenderViewHelper extends Tx_Fluid_Core_ViewHelper_Abs
         * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
         * @api
         */
-       public function render($section = '', $partial = '', $arguments = array()) {
-               if ($partial !== '') {
+       public function render($section = NULL, $partial = NULL, $arguments = array()) {
+               $arguments = $this->loadSettingsIntoArguments($arguments);
+
+               if ($partial !== NULL) {
                        return $this->viewHelperVariableContainer->getView()->renderPartial($partial, $section, $arguments);
-               } elseif ($section !== '') {
-                       return $this->viewHelperVariableContainer->getView()->renderSection($section);
+               } elseif ($section !== NULL) {
+                       return $this->viewHelperVariableContainer->getView()->renderSection($section, $arguments);
                }
                return '';
        }
 
-
+       /**
+        * If $arguments['settings'] is not set, it is loaded from the TemplateVariableContainer (if it is available there).
+        *
+        * @param array $arguments
+        * @return array
+        */
+       protected function loadSettingsIntoArguments($arguments) {
+               if (!isset($arguments['settings']) && $this->templateVariableContainer->exists('settings')) {
+                       $arguments['settings'] = $this->templateVariableContainer->get('settings');
+               }
+               return $arguments;
+       }
 }
 
-
 ?>