8353f4dbdabeb9b00bc3be1af551f3e74d607290
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / RenderViewHelper.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * ViewHelper that renders a section or a specified partial
25 *
26 * == Examples ==
27 *
28 * <code title="Rendering partials">
29 * <f:render partial="SomePartial" arguments="{foo: someVariable}" />
30 * </code>
31 * <output>
32 * the content of the partial "SomePartial". The content of the variable {someVariable} will be available in the partial as {foo}
33 * </output>
34 *
35 * <code title="Rendering sections">
36 * <f:section name="someSection">This is a section. {foo}</f:section>
37 * <f:render section="someSection" arguments="{foo: someVariable}" />
38 * </code>
39 * <output>
40 * the content of the section "someSection". The content of the variable {someVariable} will be available in the partial as {foo}
41 * </output>
42 *
43 * <code title="Rendering recursive sections">
44 * <f:section name="mySection">
45 * <ul>
46 * <f:for each="{myMenu}" as="menuItem">
47 * <li>
48 * {menuItem.text}
49 * <f:if condition="{menuItem.subItems}">
50 * <f:render section="mySection" arguments="{myMenu: menuItem.subItems}" />
51 * </f:if>
52 * </li>
53 * </f:for>
54 * </ul>
55 * </f:section>
56 * <f:render section="mySection" arguments="{myMenu: menu}" />
57 * </code>
58 * <output>
59 * <ul>
60 * <li>menu1
61 * <ul>
62 * <li>menu1a</li>
63 * <li>menu1b</li>
64 * </ul>
65 * </li>
66 * [...]
67 * (depending on the value of {menu})
68 * </output>
69 *
70 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
71 * @api
72 */
73 class Tx_Fluid_ViewHelpers_RenderViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
74
75 /**
76 * Renders the content.
77 *
78 * @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.
79 * @param string $partial Reference to a partial.
80 * @param array $arguments Arguments to pass to the partial.
81 * @return string
82 * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
83 * @api
84 */
85 public function render($section = NULL, $partial = NULL, $arguments = array()) {
86 $arguments = $this->loadSettingsIntoArguments($arguments);
87
88 if ($partial !== NULL) {
89 return $this->viewHelperVariableContainer->getView()->renderPartial($partial, $section, $arguments);
90 } elseif ($section !== NULL) {
91 return $this->viewHelperVariableContainer->getView()->renderSection($section, $arguments);
92 }
93 return '';
94 }
95
96 /**
97 * If $arguments['settings'] is not set, it is loaded from the TemplateVariableContainer (if it is available there).
98 *
99 * @param array $arguments
100 * @return array
101 */
102 protected function loadSettingsIntoArguments($arguments) {
103 if (!isset($arguments['settings']) && $this->templateVariableContainer->exists('settings')) {
104 $arguments['settings'] = $this->templateVariableContainer->get('settings');
105 }
106 return $arguments;
107 }
108 }
109
110 ?>