Wrapper Content Type
There are helpers to let you know if an item of content is the first and last of its type in a section:
firstOfType and lastOfType Helpers
These are used like:
{{#firstOfType}}
Only output if first of this content type in section
{{/firstOfType}}
{{#lastOfType}}
Only output if last of this content type in section
{{/lastOfType}}
firstInSequence and lastInSequence Helpers
Perhaps more flexible though, are these helpers which allow you to determine if an item of content is the first and last of its type in an uninterrupted sequence of content in a section.
Consider a section with the following Content Items
Order in section | Content Type Used | firstOfType | lastOfType | firstInSequence | lastInSequence |
---|---|---|---|---|---|
1 | General Content | ✅ | ⛔ | ✅ | ✅ |
2 | Wrapper Item | ✅ | ⛔ | ✅ | ⛔ |
3 | Wrapper Item | ⛔ | ⛔ | ⛔ | ⛔ |
4 | Wrapper Item | ⛔ | ⛔ | ⛔ | ✅ |
5 | General Content | ⛔ | ✅ | ✅ | ✅ |
6 | Wrapper Item | ⛔ | ⛔ | ✅ | ⛔ |
7 | Wrapper Item | ⛔ | ⛔ | ⛔ | ⛔ |
8 | Wrapper Item | ⛔ | ✅ | ⛔ | ✅ |
The firstInSequence and lastInSequence Helpers are used like:
{{#firstInSequence}}
Only output if first of this content type in an uninterrupted sequence in this section
{{/firstInSequence}}
{{#lastInSequence}}
Only output if last of this content type in an uninterrupted sequence in this section
{{/lastInSequence}}
Example
Below we have an example of 3 Accordion Items, followed by a General Content, followed by 3 more accordion items.
We use the firstInSequence
and lastInSequence
helpers to ensure the accordions are surrounded appropriately with a wrapper div.
The text/html layout has the following Handlebars code:
{{#firstInSequence}}
{{embed layout="text/before"}}
{{/firstInSequence}}
{{embed layout="text/middle"}}
{{#lastInSequence}}
{{embed layout="text/after"}}
{{/lastInSequence}}
Because this is so much shorter and easier to work with than the Programmable layout equivalent you should consider avoiding embedding alternate layouts altogether to improve performance and instead, do something like:
{#firstInSequence}}
<div class="open-wrapper"> {{/firstInSequence}}
<div class="accordion-item">
<div class="accordion-heading">{{publish element="Accordion Heading"}}</div>
<div class="accordion-content">{{{publish element="Accordion Content"}}}</div>
</div>
{{#lastInSequence}}
</div> <!-- close .open-wrapper --> {{/lastInSequence}}
text/before
Accordion Group
- Choose question
text/middle
text/middle
text/middle
text/after
General Content Added
This is here to add some different type of content between accordions
text/before
Accordion Group
- Choose question
text/middle
text/middle
text/after