Merge "[TASK] Increase version number"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / RenderViewHelper.php
1 <?php
2
3 /* *
4 * This script is backported from the FLOW3 package "TYPO3.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, either version 3 *
8 * of the License, or (at your option) any later version. *
9 * *
10 * The TYPO3 project - inspiring people to share! *
11 * */
12
13
14 /**
15 * ViewHelper that renders a section or a specified partial
16 *
17 * == Examples ==
18 *
19 * <code title="Rendering partials">
20 * <f:render partial="SomePartial" arguments="{foo: someVariable}" />
21 * </code>
22 * <output>
23 * the content of the partial "SomePartial". The content of the variable {someVariable} will be available in the partial as {foo}
24 * </output>
25 *
26 * <code title="Rendering sections">
27 * <f:section name="someSection">This is a section. {foo}</f:section>
28 * <f:render section="someSection" arguments="{foo: someVariable}" />
29 * </code>
30 * <output>
31 * the content of the section "someSection". The content of the variable {someVariable} will be available in the partial as {foo}
32 * </output>
33 *
34 * <code title="Rendering recursive sections">
35 * <f:section name="mySection">
36 * <ul>
37 * <f:for each="{myMenu}" as="menuItem">
38 * <li>
39 * {menuItem.text}
40 * <f:if condition="{menuItem.subItems}">
41 * <f:render section="mySection" arguments="{myMenu: menuItem.subItems}" />
42 * </f:if>
43 * </li>
44 * </f:for>
45 * </ul>
46 * </f:section>
47 * <f:render section="mySection" arguments="{myMenu: menu}" />
48 * </code>
49 * <output>
50 * <ul>
51 * <li>menu1
52 * <ul>
53 * <li>menu1a</li>
54 * <li>menu1b</li>
55 * </ul>
56 * </li>
57 * [...]
58 * (depending on the value of {menu})
59 * </output>
60 *
61 *
62 * <code title="Passing all variables to a partial">
63 * <f:render partial="somePartial" arguments="{_all}" />
64 * </code>
65 * <output>
66 * the content of the partial "somePartial".
67 * Using the reserved keyword "_all", all available variables will be passed along to the partial
68 * </output>
69 *
70 * @api
71 */
72 class Tx_Fluid_ViewHelpers_RenderViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
73
74 /**
75 * Renders the content.
76 *
77 * @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.
78 * @param string $partial Reference to a partial.
79 * @param array $arguments Arguments to pass to the partial.
80 * @param boolean $optional Set to TRUE, to ignore unknown sections, so the definition of a section inside a template can be optional for a layout
81 * @return string
82 * @api
83 */
84 public function render($section = NULL, $partial = NULL, $arguments = array(), $optional = FALSE) {
85 $arguments = $this->loadSettingsIntoArguments($arguments);
86
87 if ($partial !== NULL) {
88 return $this->viewHelperVariableContainer->getView()->renderPartial($partial, $section, $arguments);
89 } elseif ($section !== NULL) {
90 return $this->viewHelperVariableContainer->getView()->renderSection($section, $arguments, $optional);
91 }
92 return '';
93 }
94
95 /**
96 * If $arguments['settings'] is not set, it is loaded from the TemplateVariableContainer (if it is available there).
97 *
98 * @param array $arguments
99 * @return array
100 */
101 protected function loadSettingsIntoArguments($arguments) {
102 if (!isset($arguments['settings']) && $this->templateVariableContainer->exists('settings')) {
103 $arguments['settings'] = $this->templateVariableContainer->get('settings');
104 }
105 return $arguments;
106 }
107 }
108
109 ?>