you could create a custom list.html template. If you only want to redirect from http://example.com/fruit you have to place the template at layouts/fruit/list.html. This template is only used for the content type fruit.
If you prefer to redirect users in all content types you have to place the list template under layouts/_default/list.html.
HTML allows you to redirect users with a meta tag. Place this tag in the head of the list template and the redirection should work.
I was able to make the redirect work, but only when I created layouts/_default/list.html.
When I put the list.html in layouts/fruit/list.html the resulting index.html in fruit/index.html is blank.
Any ideas why this doesn’t work for the fruit content type specifically?
For the layouts/fruits template folder to work, you have to specify that you want to use this template folder. In your front matter, in YAML:
type: fruit
layout: list
The type variable will make it so hugo will first look into the layouts/type folder. And it will pick the layout.html file. (here, it’ll try to pick layouts/fruit/list.html, and if it doesn’t find it, it will use layouts/_default/list.html).
Normally, you can just use the section name (the folder your content file is in), or I believe you can specify the section in the front matter - but I prefer to use type everywhere.
After browsing the docs I found a solution that I tested locally. Create a new folder section at layouts/. Now add an HTML file with the name of the content type, in our case fruit.html.
Now you should be able to redirect to specific sections.
If I understand what you’re asking, I think this could be solved in a much easier way without using meta refresh and quasi-redirects, @mrsmith. Keep your template the same at layouts/fruit/single.html and then do the following in your config.toml:
@mrsmith Ah, got it. So basically you just wanted a list page for the fruit content type at mysite.com/fruit/. Here is the cascade (as taken from the docs):