Collections render on index, not subdirectory (Resolved)


#1

I want to have my collections show up at /links, but localhost shows the list of all the items in my collection instead of the loop containing my posts.

What did I miss? I have the following configuration with dummy content.

collections:
  links:
    output: true

layout: links
title: Bacon
links: https://en.wikipedia.org/wiki/Bacon
---
Spicy jalapeno bacon ipsum dolor amet pork belly sausage bresaola ham brisket. Ground round alcatra cupim meatball shankle landjaeger hamburger flank jowl biltong. Meatball doner pork belly picanha capicola, ground round bacon cow chicken spare ribs landjaeger. Picanha rump pork belly filet mignon. Ball tip venison drumstick, chicken short loin flank pancetta tri-tip hamburger landjaeger spare ribs t-bone. Leberkas kevin landjaeger, ball tip alcatra fatback prosciutto ribeye tenderloin cow doner picanha porchetta capicola beef ribs.

My layout is as follows:

---
layout: default
title: Links
---

Links I have saved:

{% for item in site.tags.links %}
  <p><a href="{{ links.url }}">{{ links.title }}</a></p>
  <p>{{ links.content }}</p>
{% endfor %}

#2

The object you’re looping over is wrong. Instead of site.tags.links use site.links


#3

you are doing for item but then you do links.url it should be item.url, item.title etc.


#4

I’ve updated _config.yml to output a permalink at /links/ which solves the first issue, but now my URLs point there, ignoring the for loop.

Updated code from _layouts/links.html is as follows:

---
layout: default
---

{% for link in site.links %}
  <p><a href="{{link.url}}">{{link.title}}</a></p>
{% endfor %}

@rdyar Using item.url as you described gives the same result.


#5

not real clear on what you are doing, is there a repo to look at?

Maybe you did a a permalink in the defaults in the config that is just /links/ and so they are all getting that - maybe it needs to be /links/:name or something similar - I don’t use defaults so I am not real sure on the formatting, but maybe it is doing what you are telling it to, rather than what you want.

My comment about the for loop is that the thing you say after for needs to be the same thing you use to call the different things like title or url. Your second example is correct, first one not so much. Doesn’t matter if it is item, link or any other word you want to use, but you then need to use that same word to call the objects(?) you want. I like item as it is generic, often you will see people use post and then people end up thinking that post.title is actually a thing when it is not (except in a for loop with post as the key(?)).


#6

Testing repo is here so you can take a look.


#7
collections:
 links:
   output: true
   permalink: /links/

I think this is a problem - every collection item will have the url set to /links/ so if there is more than one item they will overwrite each other. You need something else in the path to make it unique, something like /links/:name though I am not sure that is the correct formatting.

If that isn’t the problem, is there a link to a page on the rendered site that shows the issue? like what is the output of the for loop?


#8

@rdyar is correct on your collection config being off… specifically the permalink.

What I typically do is use permalink: /:collection/:path/

This will inject the collection name (in your case links) followed by the path of the collection document (the slugified filename).

So if you have _links/bacon.md you’d get _site/links/bacon/index.html when Jekyll builds the site.


#9

You also have some layout confusion going on.

What is currently in _layouts/links.html looks more like a index page for links… not a layout for the link collection documents.

---
layout: default
---

{% for link in site.links %}
  <p><a href="{{ link.url }}">{{ link.title }}</a></p>
{% endfor %}

For example there’s no {{ content }} to pull in. It’s just going to spit out bacon and ham pages that have links to all of the other documents.

You probably want to use _layouts/links.html for a “links” index page (eg. /links/index.html) and then create a link page specific layout:

_layouts/link.html

---
layout: default
---

<h1><a href="{{ page.url }}">{{ page.title }}</a></h1>
{{ content }}

_links/bacon.markdown

---
layout: link
title: Bacon
url: https://en.wikipedia.org/wiki/Bacon
---

Spicy jalapeno bacon ipsum dolor amet pork belly sausage bresaola ham brisket. Ground round alcatra cupim meatball shankle landjaeger hamburger flank jowl biltong. Meatball doner pork belly picanha capicola, ground round bacon cow chicken spare ribs landjaeger. Picanha rump pork belly filet mignon. Ball tip venison drumstick, chicken short loin flank pancetta tri-tip hamburger landjaeger spare ribs t-bone. Leberkas kevin landjaeger, ball tip alcatra fatback prosciutto ribeye tenderloin cow doner picanha porchetta capicola beef ribs.

#10

Took another run at this and after walking through a Cloud Cannon tutorial to check myself, everything appears to be working. :raised_hands:t3:

Didn’t click with me initially that a separate page other than the index had to exist at the root of the site. :man_facepalming:t2:

I think I get it now. :nerd_face:

Update: Bah, it’s getting it’s own layout.