Render ViewHelper <f:render>
Go to the source code of this ViewHelper: RenderViewHelper.php (GitHub).
Note
While a partial or section can be rendered using this ViewHelper, a layout can only be included using the Layout ViewHelper <f:layout>.
Table of contents
Rendering a partial
See also
The render ViewHelper can be used with the argument partial to render the content of a "partial". A partial is a separate Fluid file.
<f:render partial="Footer" arguments="{_all}"/>
During rendering the content of file
packages/
will be rendered with all variables that are also available in the main template.
It is possible to render a partial within a partial or layout as well. For example the footer partial could look like this:
<footer class="my-footer">
<f:render partial="Navigation/FooterMenu" arguments="{_all}"/>
</footer>
When the argument partial
contains a slash /
the partial will be searched in a subfolder. The partial
from the above example will therefore be expected in file
packages/
.
Configuring the path in which to save the partials
- Partials used to display pages with the TypoScript object
PAGEVIEW are
always found in folder
Partials
within the path that has been defined in property paths.[priority]. - Partials used to display content elements or pages using the TypoScript object FLUIDTEMPLATE are searched in the paths defined in property partialRootPaths.
- In Extbase plugins the paths to the partials are configured in
plugin.tx_myextension_someplugin.view.partialRootPaths.[priority].
If not path is defined here there is a fallback to folder
EXT:
.my_ extension/ Resources/ Private/ Partials
Rendering a section
When the render ViewHelper is used with the argument section the content of a Section ViewHelper <f:section> can be rendered.
<f:render section="SomeSection"/>
<f:section name="SomeSection">
This is the section.
</f:section>
Rendering sections in layouts
If the section is rendered from within a layout file the section can be defined in the template using the layout. Since usually several templates use the same layout, it can be helpful to mark the render tag as optional. It is also possible to provide a default value to be displayed if the section was not found in the template. You can use the content of the tag or the argument default.
<f:render section="Header" optional="true">
<f:render partial="Header" arguments="{_all}"/>
</f:render>
<f:render section="Breadcrumb" optional="true"/>
<f:render section="Main"/>
In this example the templates may define a section called "Header" to override the default header rendered from a partial.
If the template defines no section named "Breadcrumb" that section is just ignored.
All templates have to define the section "Main" otherwise there is an error.
Template 1 just defines some content:
<f:layout name="PageLayout"/>
<f:section name="Main">
<main>Main content of Template 1</main>
</f:section>
<f:layout name="PageLayout"/>
<f:section name="Header">
<header>My Special header</header>
</f:section>
<f:section name="Breadcrumb">
<f:render partial="Navigation/Breadcrumb" arguments="{_all}">
</f:section>
<f:section name="Main">
<main>Main content of Template 1</main>
</f:section>
Rendering a section from a (different) partial
If both arguments section and partial are used a section found in a partial can be rendered.
Arguments
arguments
-
- Type
- array
- Default
- array ( )
Array of variables to be transferred. Use {_all} for all variables
contentAs
-
- Type
- string
If used, renders the child content and adds it as a template variable with this name for use in the partial/section
debug
-
- Type
- boolean
- Default
- true
If true, the admin panel shows debug information if activated,
default
-
- Type
- mixed
Value (usually string) to be displayed if the section or partial does not exist
delegate
-
- Type
- string
Optional PHP class name of a permanent, included-in-app ParsedTemplateInterface implementation to override partial/section
optional
-
- Type
- boolean
- Default
- false
If true, considers the *section* optional. Partial never is.
partial
-
- Type
- string
Partial to render, with or without section
section
-
- Type
- string
Section to render - combine with partial to render section in partial