Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Bricolage: users

Nested list with Template Toolkit (2.0.1)

 

 

Bricolage users RSS feed   Index | Next | Previous | View Threaded


catalyst at mikeraynham

May 15, 2011, 4:55 AM

Post #1 of 8 (641 views)
Permalink
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


david at kineticode

May 15, 2011, 3:21 PM

Post #2 of 8 (598 views)
Permalink
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


phillip at communitybandwidth

May 15, 2011, 4:49 PM

Post #3 of 8 (598 views)
Permalink
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.


catalyst at mikeraynham

May 16, 2011, 12:22 AM

Post #4 of 8 (593 views)
Permalink
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
>


david at kineticode

May 16, 2011, 9:25 AM

Post #5 of 8 (598 views)
Permalink
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


david at kineticode

May 16, 2011, 9:26 AM

Post #6 of 8 (597 views)
Permalink
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


ps at phillipadsmith

May 17, 2011, 6:54 AM

Post #7 of 8 (591 views)
Permalink
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


catalyst at mikeraynham

May 17, 2011, 7:18 AM

Post #8 of 8 (595 views)
Permalink
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
>

Bricolage users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.