Structures template from Singles.
Fluid allows a handful of structures to render
dynamic parts of templates. Each method is
uniquely suited for precise use cases:
* No difference between inline and tag argument syntax
With the exception of using quotes, which must still be escaped, there is no difference between the following
examples of syntax:
{f:render(partial: 'Structures', section: 'ValidSection')}
{f:render(partial="Structures", section="ValidSection")}
{f:render(partial="Structures" section="ValidSection")}
* Passing arguments in inline mode
The following line:
Tag: "{dynamicSection}"
Is identical in behavior to:
Pass: "{dynamicSection -> f:format.raw()}"
Which can also be expressed as:
Pipe: "{dynamicSection | f:format.raw()}"
Pipe, multiple levels: "{dynamicSection | f:format.raw() | f:format.htmlspecialchars()}"
In other words, tag contents can be passed also in inline mode, using either the combined "->" operator or standard pipe "|".
* Loop
You can loop through arrays in two ways; as standard
arrays and using a grouping by key to create "chunks":
{item}
{myGroupKey}:
{item.property}
* Optional sections
There are two main ways to get this behavior:
This section exists and is rendered:
Expects no output because section name is invalid:
And:
Dynamic section name:
Bad dynamic section name, expects fallback:
The same works for partials:
This section exists and is rendered:
Expects no output because section name is invalid:
And:
Dynamic section name:
Bad dynamic section name, expects fallback:
* Inline render with condition
Render statements can be written as inline
expressions and conditioned by a clause:
Will render: {f:render(section: 'Section') -> f:if(condition: '1 == 1')}
Will render, clause reversed: {f:render(section: 'Section') -> f:else() -> f:if(condition: '1 == 0')}
Will not render: {f:render(section: 'Section') -> f:if(condition: '1 == 0')}
* Else-if
Fluid allows the `f:else` ViewHelper to also include
a condition clause that must be true for that `f:else`
to be rendered. Multiple `f:else` can then exist. The
else-if approach only works when using full tag mode.
Is not rendered
Not rendered either
This `f:else` was rendered
Rendered only if no other `f:else` was matched
* Switch
Although Fluid allows both if-then-elseif-else as well
as dynamic section names which in practice should mean
you can completely avoid a `switch`-like control. But,
when you do need a switch, one can be implemented as:
- Matched switch
The value was "1"
The value was "2"
The value was "3"
This text must not be shown
- Unmatched switch
The value was "1"
The value was "2"
The value was "3"
The unmatched value case triggered
- Nested switch
The value was "1"
The value was "2"
The value was "3"
The value was "1"
The "b" nested switch case was triggered
The "c" nested switch case was triggered
This text must not be shown
This text must not be shown
Dynamically suffixed section
Just a section
Valid section
Invalid section, output not shown