Generating a gallery

50 views
Skip to first unread message

BenC

unread,
Mar 19, 2010, 4:39:00 AM3/19/10
to Bonsai
A few more hours, a few more questions...

I'd like to generate a gallery by iterating over the children of a
particular page. Using #children, this is trivially easy. However, I'd
like to further iterate over a consistently named image folder in each
child folder, like 'images', and pull those out. Sample code:

{{#children}}
{{#images}}
<img src="{{path}}" alt="{{name}}">
{{/images}}
{{/children}}

With a directory structure:
1.Top Level
|--1.Sub Level 1
| `-- images
`--2.Sub Level 2
`---> images

This doesn't work, I suspect because mustache doesn't like it. Any
alternative thoughts?

Ben Schwarz

unread,
Mar 19, 2010, 4:49:02 AM3/19/10
to tiny...@googlegroups.com
I found that when I iterated over an item and rendered a partial that the partial would better-set the context.
I guess this is a mustache quirk that I should've passed onto Mr Wanstrath. (I'll do so now)

{{# children}}
{{> partials/projects/item}}
{{/ children}}

Worked for me :)

Keep asking questions, I'd like to get some common use stuff into the default templates.

> To unsubscribe from this group, send email to tinytree+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

BenC

unread,
Mar 19, 2010, 4:52:15 AM3/19/10
to Bonsai
Just a quick comment: images starting with a number have the number
stripped off when they are copied. Seems like something in page.rb is
ignoring filetype when looking for the prepended numbers used in page
hierarchy. This was not the source of my problem, though.

Ben Schwarz

unread,
Mar 19, 2010, 4:53:33 AM3/19/10
to tiny...@googlegroups.com
Thanks for the report, perhaps you can log it as an issue on github for me? :)

BenC

unread,
Mar 19, 2010, 4:57:45 AM3/19/10
to Bonsai
Will do. Thanks.

BenC

unread,
Mar 19, 2010, 1:59:25 PM3/19/10
to Bonsai
I've set this up as suggested, so that my partial has:

{{#images}}
<img src="{{path}}" alt="{{name}}" />
{{/images}}

and is called from the parent template inside the {{# children}}
section, but I'm still not having much success.

Looking at the mustache demo, http://defunkt.github.com/mustache/#demo,
it seems like the nested sections occur with a hash value that is an
array (the value of the "items" key). Is there any reason this would
have an effect?

Ben Schwarz

unread,
Mar 19, 2010, 8:06:38 PM3/19/10
to tiny...@googlegroups.com
I made a little demo: 

{{#children}}
  {{#images}}
    <img src="{{path}}" alt="">
  {{/images}}
{{/children}}


{
  "children":[
    {"name": "Page name", "images":[{"path": "/path/to/image/1"}]},
    {"name": "Page name", "images":[{"path": "/path/to/image/2"}]},
    {"name": "Page name", "images":[{"path": "/path/to/image/3"}]}
  ]
}

Which renders as expected. 

If you want to zip-up your site and send over that page / content / image set I'd be happy to have a 
look to figure out what is happening. 

BenC

unread,
Mar 22, 2010, 7:43:56 PM3/22/10
to Bonsai
I'm still having trouble so I created an example setup called
recursive_images_test.zip and sent it your way.

On Mar 19, 5:06 pm, Ben Schwarz <ben.schw...@gmail.com> wrote:
> I made a little demo:
>
> {{#children}}
>   {{#images}}
>     <img src="{{path}}" alt="">
>   {{/images}}
> {{/children}}
>
> {
>   "children":[
>     {"name": "Page name", "images":[{"path": "/path/to/image/1"}]},
>     {"name": "Page name", "images":[{"path": "/path/to/image/2"}]},
>     {"name": "Page name", "images":[{"path": "/path/to/image/3"}]}
>   ]
>
> }
>
> Which renders as expected.
>
> If you want to zip-up your site and send over that page / content / image set I'd be happy to have a
> look to figure out what is happening.
>
> On 20/03/2010, at 4:59 AM, BenC wrote:
>
>
>
> > I've set this up as suggested, so that my partial has:
>
> > {{#images}}
> >  <img src="{{path}}" alt="{{name}}" />
> > {{/images}}
>
> > and is called from the parent template inside the {{# children}}
> > section, but I'm still not having much success.
>

> > Looking at the mustache demo,http://defunkt.github.com/mustache/#demo,

Ben Schwarz

unread,
Mar 22, 2010, 8:22:13 PM3/22/10
to tiny...@googlegroups.com
I never got to this over the weekend to explore it further.
I'll get to it when I can.
Reply all
Reply to author
Forward
0 new messages