Re: [nesta] Listing categories
- From:
- Graham Ashton
- Date:
- 2012-02-17 @ 16:28
On 17 Feb 2012, at 15:35, Jake Subs wrote:
> http://www.jrayson.co.uk/blog
I love the design. Very swish.
> I'd like to output a list of article categories on the blog page, any
> idea how I do this?
I suppose the question is, which pages are your category pages? Nesta
would allow you to have category pages at any location in your site, and
I'm not sure that you'd necessarily want to include them all in the same
list.
In other words, these could all be categories:
/blog/design
/blog/design/css
/blog/design/css/tips-n-tricks
If you can describe which pages you'd like to include we can have a crack
at some Ruby for you.
But here are a few examples anyway...
In a Haml template, you can loop over all the pages on your site like this:
- Page.find_all.each do |page|
%a{ :href => page.abspath } page.heading
If you wanted to skip some you could put a bit of logic in the loop to
avoid them. This loop will skip any pages whose absolute paths have more
than one '/' in them. Almost certainly not what you want, and unlikely to
return the pages in alphabetical order. But you get the idea.
- Page.find_all.each do |page|
- next unless page.abspath.count('/') == 1
%a{ :href => page.abspath } page.heading
The best (i.e. cleanest) approach would be to work out which pages you
want to display in a helper method. This would go in app.rb:
module Nesta
class App
helpers do
def my_category_pages
Page.find_all.select do |page|
page.abspath.count('/') == 1
end
end
end
end
end
Your template would then be simplified to this:
- my_category_pages.each do |page|
%a{ :href => page.abspath } page.heading
If there's no simple rule for what to include you might want to control it
manually. There's a special metadata key called "Flags" that'd be perfect
for this. You could add this to the top of each page that you want to show
up:
Flag: shown-on-blog
Flags is just a comma separated list; you can put what you like in it.
Then your my_category_pages helper could do this:
def my_category_pages
Page.find_all.select { |p| p.flagged_as?('shown-on-blog') }
end
You could sort the list by page heading too if that made sense.
Let us know what logic would make sense for you though, and we can improve
on that.
--
Graham Ashton
Founder, The Agile Planner
http://theagileplanner.com | @agileplanner | @grahamashton
Re: [nesta] Listing categories
- From:
- Jake Subs
- Date:
- 2012-02-18 @ 20:48
On 17 February 2012 16:28, Graham Ashton <graham@effectif.com> wrote:
> I love the design. Very swish.
Thank you. I 'borrowed' the inspiration from no.3 of Four Techniques
for Combining Typefaces. The fonts are from Google Web Fonts. The drop
shadows are courtesy CSS3 ;)
http://www.typography.com/ask/recentTopic.php?rtID=92
I plan to make very simple, 2 column responsive Nesta theme with 3
breakpoints. Once I've worked out how to do it properly.
>> I'd like to output a list of article categories on the blog page,
> I suppose the question is, which pages are your category pages?
Of course, I can just make the pages for the category, and then create
a link to the page. Doh.
My next problem is that I'm getting this error if I have more than one
category on a page:
NoMethodError at /css
undefined method `downcase' for nil:NilClass
file: models.rb location: block in categories line: 256
Very odd.
> In other words, these could all be categories:
> /blog/design
> /blog/design/css
> /blog/design/css/tips-n-tricks
> If you can describe which pages you'd like to include we can have a
crack at some Ruby for you.
That's very kind. I won't need them for now, as single tier categories
are more than adequate.
> But here are a few examples anyway...
Thank you for the examples as well. I'll have a good read through and
attempt more sophisticated categorisations at a later date.
many thanks, again, Jake
--
[~] Jake Rayson
[w] www.jrayson.co.uk
[e] subs@growdigital.org
[t] @growdigital
Re: [nesta] Listing categories
- From:
- Graham Ashton
- Date:
- 2012-02-18 @ 20:58
On 18 Feb 2012, at 20:48, Jake Subs wrote:
> My next problem is that I'm getting this error if I have more than one
> category on a page:
>
> NoMethodError at /css
> undefined method `downcase' for nil:NilClass
> file: models.rb location: block in categories line: 256
>
> Very odd.
Have you got any files in content/pages that don't set a heading? I
haven't checked the code, but this looks suspiciously like the error that
gets raised when Nesta can't get a heading for a page.
--
Graham Ashton
Founder, The Agile Planner
http://theagileplanner.com | @agileplanner | @grahamashton
Re: [nesta] Listing categories
- From:
- Jake Subs
- Date:
- 2012-02-18 @ 21:02
On 18 February 2012 20:58, Graham Ashton <graham@effectif.com> wrote:
>> My next problem is that I'm getting this error if I have more than one
>> category on a page:
>> NoMethodError at /css
> Have you got any files in content/pages that don't set a heading? I
haven't checked the code, but this looks suspiciously like the error that
gets raised when Nesta can't get a heading for a page.
Bingo, that was it. Thank you :)
--
[~] Jake Rayson
[w] www.jrayson.co.uk
[e] subs@growdigital.org
[t] @growdigital