2

I come from expression engine and what I want to do is the following: I have a channel filled with entries. All I want to do is to list all these entries on a page. However, I don't want to link through to a detail page. So I disable the "Entries have their own URL's".

Now I can link to this channel by linking to its handle in my url.

Problem now is that I use a structure to build up my navigation. And you can't link to a channel in a structure, only to its entries. So I need to create a (useless) extra single section to link to and list all entries from my channel in that single. Shouldn't it be simpler than that?

I didn't find a better way to handle navigations yet.

2

The reason why there's no automatically set url and template for channel index pages is because Craft tries to be as flexible as possible. In many use cases for channel sections you don't want a index page at all or you could also need multiple of them.

But you already chose a very solid approach by setting up a structure section for your navigation. And no, you don't have to create useless singles for each channel index. I'd rather use entries of that structure itself and would just set up a new entry type for your indexes. See this article in the Craft Docs on how to link templates to entry types.

I think it's really nice to have all the site main pages together in one structure. You can easily add fields to your index pages and have your client edit all this rather static content in here.

You can also add you home page to that structure. See this Q/A for how to do that.

1

Craft is very flexible about what you can display where. You can display channel or structure entries virtually anywhere using:

{% for entry in craft.entries.section('mySectionHandle') %}
    {{ entry.title }}
    etc ...
{% endfor %}

Just paste this into one of your structure templates (or any template). If you only want it to display in one structure entry, then you can place a conditional in that template that only displays the content based on a specific uri segment or the defined Entry Type for that page/entry or both.

To check for uri segment:

{% if craft.request.getSegment(2) == "mySection" %}...{% endif %}

to check for entry type:

{% if entry.type == "myEntryType" %}...{% endif %}

Update You can also just create an index page in your templates folder in that sections folder (i.e. '/craft/templates/mysection/index.html') and link to that directly (i.e. <a href="mysection">mysection title</a>).

  • Yes, that's pretty basic but that's not my point. Let me try to be more clear. Your method is how i do things now. I make a single and a channel and i fetch all entries from my channel in my single template. But that requires me to have a single AND a channel. It should be possible to do this without the single. The solution to this is to just be able to link to channels and a template for that channel in a structure. I hope I'm a bit more clear now? :) – Tom De Smet Nov 12 '14 at 21:10
  • Channels do not have an index or landing page by default. You need to create one. But that index or landing page does not have to be a single, it can be a specific entry in your existing structure. It can also just exist as an index.php file in your templates folder (i.e. mysection/index.html). – Douglas McDonald Nov 12 '14 at 21:15
  • Hmmm. Need to take a closer look at structures. Thanks for your answer, i'm going to do some testing. – Tom De Smet Nov 12 '14 at 21:47
  • Have a look at Entry Types in particular. They allow you to combine vastly different types of content within the same structure. And you can create a clause or include different sub-templates to display that content by checking entry.type. – Douglas McDonald Nov 12 '14 at 22:07
  • Yes, I see what you mean now. Instead of listing singles into a structure to use as my navigation, I could of used different entry types in my structure. But the "problem" if I may call it that, stays the same. I still need another sort of page (being a single or a structure entry) to list all my channel entries on. Wouldn't it be usefull if a channel could have a channel index or something that you can point to from a structure? Like my original idea? There are multiple ways to do what I want to be done, but it still involves adding one extra structure page or single section that shouldn't be – Tom De Smet Nov 12 '14 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.