-
Notifications
You must be signed in to change notification settings - Fork 51
HOWTO: How to Create a Simple Nested List
In Bricolage, container elements may be specified as subelements of themselves – they can be self referential. This makes it easy to create simple hierarchical lists, which may then be output in a variety of formats, such as unordered and ordered lists in HTML.
The HOWTO explains how to create a simple nested list that can be used to create a bullet list with an arbitrary number of levels.
Define a new Element Type:
Content Type | Key Name | Name |
---|---|---|
Subelement | bullet_list | Bullet list |
Add a custom field:
Widget Type | Key Name | Label | Min. Occur. |
---|---|---|---|
Text Box | bullet_point | Bullet point | 1 |
Save the bullet_list element, then add the bullet_list element as a subelement of itself. See this example.
Define /bullet_list.tt
template:
[%# Start UL %]
<ul>
[%~ FOREACH e IN element.get_elements() %]
[%~ IF e.get_value() %]
<li>
[%~ e.get_value() %]
[%~ burner.display_element(loop.next)
IF loop.next.is_container() ~%]
</li>
[%~ END %]
[%~ END %]
</ul>
[%# End UL %]
The bullet_list
element can now be included in a story element. Authors can create multi-level bullet lists by nesting one or more bullet lists.
For a more complex Mason template example which allows different list types (ordered or unordered), and also allow items to have multiple paragraphs, links to other documents, and code blocks, see this old Bricolage site template: