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:
* 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