I've recently started to experiment with Bricolage, and one of the first
things that I wanted to do was define a method to allow the creation of
nested lists (such as unordered and ordered lists).
I came up with the following method, and would like to check if it is a
sane way to do it. If it is, then it may be of use to others.
Define new Element Type:
Content type: Subelement
Key name: bullet_list
Name: Bullet list
Add a custom field:
Widget type: Text Box
Key Name: bullet_point
Label: Bullet point
Min. Occur.: 1
Save the bullet_list element, then add the bullet_list element as a
subelement of itself.
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 then be included in a story element. Nested
lists of arbitrary lengths are created by adding bullet_list and
bullet_point elements. My test produced this valid HTML:
<ul>
<li>Level 1-1</li>
<li>Level 1-2
<ul>
<li>Level 2-1</li>
<li>Level 2-2
<ul>
<li>Level 3-1</li>
<li>Level 3-2
<ul>
<li>Level 4-1</li>
<li>Level 4-2</li>
</ul>
</li>
<li>Level 3-3</li>
<li>Level 3-4</li>
</ul>
</li>
<li>Level 2-3</li>
<li>Level 2-4</li>
</ul>
</li>
<li>Level 1-3</li>
<li>Level 1-4</li>
</ul>
Regards,
Mike
things that I wanted to do was define a method to allow the creation of
nested lists (such as unordered and ordered lists).
I came up with the following method, and would like to check if it is a
sane way to do it. If it is, then it may be of use to others.
Define new Element Type:
Content type: Subelement
Key name: bullet_list
Name: Bullet list
Add a custom field:
Widget type: Text Box
Key Name: bullet_point
Label: Bullet point
Min. Occur.: 1
Save the bullet_list element, then add the bullet_list element as a
subelement of itself.
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 then be included in a story element. Nested
lists of arbitrary lengths are created by adding bullet_list and
bullet_point elements. My test produced this valid HTML:
<ul>
<li>Level 1-1</li>
<li>Level 1-2
<ul>
<li>Level 2-1</li>
<li>Level 2-2
<ul>
<li>Level 3-1</li>
<li>Level 3-2
<ul>
<li>Level 4-1</li>
<li>Level 4-2</li>
</ul>
</li>
<li>Level 3-3</li>
<li>Level 3-4</li>
</ul>
</li>
<li>Level 2-3</li>
<li>Level 2-4</li>
</ul>
</li>
<li>Level 1-3</li>
<li>Level 1-4</li>
</ul>
Regards,
Mike