Mailing List Archive

Nested list with Template Toolkit (2.0.1)
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
Re: Nested list with Template Toolkit (2.0.1) [ In reply to ]
On May 15, 2011, at 4:55 AM, Mike Raynham wrote:

> 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.

Yes, this works. In the past, I've also made lists that are a bit more general, allowing one to select what type of list (ordered or unordered) and also allow items to have multiple paragraphs, links to other documents, and code blocks. Here's the old Bricolage site template:

https://github.com/bricoleurs/bricolagecms-templates/blob/master/templates/XHTML/list.mc

There used to be a page on the site that showed element relationships graphically; Phillip, what happend to all that stuff? You should be able to get the idea, though. In case you need something more flexible.

Best,

David
Re: Nested list with Template Toolkit (2.0.1) [ In reply to ]
On 2011-05-15, at 6:21 PM, David E. Wheeler wrote:

> Phillip, what happend to all that stuff?


It's there, just not linked from anywhere.
Re: Nested list with Template Toolkit (2.0.1) [ In reply to ]
Thanks David - there are some nifty ideas in your example. Is $m a
Mason specific variable?


Regards,

Mike

On 15/05/11 23:21, David E. Wheeler wrote:>
> Yes, this works. In the past, I've also made lists that are a bit more general, allowing one to select what type of list (ordered or unordered) and also allow items to have multiple paragraphs, links to other documents, and code blocks. Here's the old Bricolage site template:
>
> https://github.com/bricoleurs/bricolagecms-templates/blob/master/templates/XHTML/list.mc
>
> There used to be a page on the site that showed element relationships graphically; Phillip, what happend to all that stuff? You should be able to get the idea, though. In case you need something more flexible.
>
> Best,
>
> David
>
Re: Nested list with Template Toolkit (2.0.1) [ In reply to ]
On May 16, 2011, at 12:22 AM, Mike Raynham wrote:

> Thanks David - there are some nifty ideas in your example. Is $m a Mason specific variable?

Yes, it is.

David
Re: Nested list with Template Toolkit (2.0.1) [ In reply to ]
On May 15, 2011, at 4:49 PM, Phillip Smith wrote:

>> Phillip, what happend to all that stuff?
>
>
> It's there, just not linked from anywhere.

Why not? That means I can't find them.

David
Re: Nested list with Template Toolkit (2.0.1) [ In reply to ]
On 2011-05-16, at 12:26 PM, David E. Wheeler wrote:

> On May 15, 2011, at 4:49 PM, Phillip Smith wrote:
>
>>> Phillip, what happend to all that stuff?
>>
>>
>> It's there, just not linked from anywhere.
>
> Why not? That means I can't find them.

Because the main purpose of the site re-design was to make things *simple* :-P

Maybe those pages should move to the Wiki?

--
Phillip Smith
http://phillipadsmith.com
http://twitter.com/phillipadsmith
http://linkedin.com/in/phillipadsmith
Re: Nested list with Template Toolkit (2.0.1) [ In reply to ]
Hi Phillip,

If you can post the links, I'll have a look at adding them to the wiki -
I'm currently doing a bit of work on it.


Regards,

Mike

On 17/05/11 14:54, Phillip Smith wrote:
>
> On 2011-05-16, at 12:26 PM, David E. Wheeler wrote:
>
>> On May 15, 2011, at 4:49 PM, Phillip Smith wrote:
>>
>>>> Phillip, what happend to all that stuff?
>>>
>>>
>>> It's there, just not linked from anywhere.
>>
>> Why not? That means I can't find them.
>
> Because the main purpose of the site re-design was to make things *simple* :-P
>
> Maybe those pages should move to the Wiki?
>
> --
> Phillip Smith
> http://phillipadsmith.com
> http://twitter.com/phillipadsmith
> http://linkedin.com/in/phillipadsmith
>