Log in Sign up

Getting a list of pages without using menu

I'm struggling to do something with a template that I thought would be easy but is turning out to be harder than I thought.

Specifically, I'm trying to create pages (not posts) for projects that I've worked on in the past. I don't want these to be in the site's main menu, so I'm hiding them with Menu: no, as instructed.

However, in doing this I seem to completely lose the ability to surface the page elsewhere. As far as I can tell pages themselves can't be embedded into other pages, and I'm unable to get an index to this now hidden page at all.

I also tried instead making all the projects their own posts but in a hidden folder, but ran into the same issue. Them being hidden fully excludes them for being accessed in any list.

Additionally, I was surprised to find that #all_entries doesn't return any pages, even if the page is visible. The IsPage key in the object made me think this wouldn't be the case, but alas.

What would be nice is if there was a way to just get a list of pages for the site. I think you could implicitly exclude pages in that list that state Menu: no, but could also provide an override like InPageList that would allow pages to be hidden from the global menu but able to be indexed elsewhere.


7 months ago, 4 replies   Edit question

I had a similar issue... Here's my clunky workaround for this:

  1. I created an html page (i.e. "pages.html" in the template editor with this code:
<!DOCTYPE html>
<html>
  {{> head}}
  <body>
    {{#menu}}
       {{#metadata.apples}}
     <a href="{{{url}}}">{{label}}</a>
      {{/metadata.apples}}
 {{/menu}}
  </body>
</html>

(Obviously you'll need to adjust the above to include whatever wrapper your template uses, like > head, etc.)

Which will list all pages set with metadata "apples" and menu set on i.e.:

Menu: yes
apples: yes

What this does is when you go to the website.com/pages it'll show a list of all pages with metadata "apples: yes" set.

You can easily add multiple metadata to list pages in sections, i.e.

  {{#metadata.apples}}
  <a href="{{{url}}}">{{label}}</a>
  {{/metadata.apples}}
    
     {{#metadata.oranges}}
  <a href="{{{url}}}">{{label}}</a>
  {{/metadata.oranges}}

Or do multiple pages.html, etc.

Obviously this isn't the most elegant way of doing it and it requires pages to have menu: yes (I don't use {{menu}} in my nav since I'm using my own hardcoded menu..

What with more and more folks using Digital Gardens n such on their blogs I'm hopeful David will come up with a far easier way to handle showing lists of pages eventually.

(I also hope David will allow the use of [tag] folders under pages which would make it easy to move pages around into tagged sections and therefore allow the use of {{{#tag.apples}} to list apple pages?)

Ray

Answered 7 months ago · Edit answer

@ray Yeah I think your answer boils down to "use #menu but dont show the default menu on other pages so you can control what gets shown", which is where I'm also landing for now. #menu seems to be the only way to get a list of pages, and those pages have to explictly not have Menu: no.

Answered 7 months ago · Edit answer

Right... For what it's worth on another Blot site I use posts for everything including pages. Just makes it a lot easier to display "pages" when they're posts then you can use all tag & metadata selectors, etc. etc to display a range of pages.

In this case I define those post "pages" with metadata pages: yes so it makes it easy to filter out/in on various locations.

Ray

Answered 7 months ago · Edit answer

@Ray I also tried this but the issue that I ran into was that I had pages I didn't want to be published as posts. So I made them hidden, but that then excludes them from #allEntries.

If there was some way to embed/transclude any page/post into another one I think that would work, because you could still surface hidden pages/posts.

Answered 7 months ago · Edit answer