[SOLVED] Creating Alternate View of Taxonomy

Hello All,

I’ve got my taxonomy working pretty well:

//localhost:1313/authors/<id>/

This works like a champ no problem. However, I am showing a thumbnail in this view, and I want to enable the user to click on it to get the full picture. So essentially creating a picture viewer for this taxonomy term:

//localhost:1313/authors/detail/<id>/

How does one go about doing this? The closest I have found is to create a /content/authors/detail/<id>/_index.md in the root, but this seems cumbersome. I am also creating a theme and would like to keep this generalized without forcing end users to create their own directory structure for basic/expected functionality, if that makes sense.

Is this possible? Thank you in advance for any assistance you can provide. :+1:

There seems to be two questions here:

  1. How to add Data to taxonomies without Front Matter (_index.md)?
  2. How to create an extra HTML page (detail) alongside the default one.

1. How to add Data to taxonomies without Front Matter (_index.md)?

You could have a data file named after your taxonomy term’s id. I’m not sure if it would make easier for your theme users to maintain, but it keeps you out of the Front Matter structure.
Then, from your templates, you’d have to grab the right data file and content using the taxonomy term ID.

2. How to create an extra HTML page alongside the default one.

You will need to add a new custom output format. Call it detail for example, and have it use the HTML media type. Then create a template for it and set it on your taxonomy pages.
Checkout the doc I think it has everything you need to do the preceding.
You might need to use some sort of url rewriting mechanism to have this output format served at the wished… (rather than `/authors//detail.html)

2 Likes

Hi @regis thank you for your assistance! It is much appreciated.

I also apologize if I didn’t describe this in enough detail or caused confusion here. What I am looking to achieve is to simply create another view with the same data.

Right now I have the primary view rendering exactly as desired from themes/<theme>/layouts/authors/author.html. In this file, I have a link to /authors/detail/<id> that shows the same information, but in a different view: themes/<theme>/layouts/authors/view.html

However, the only way that I can see doing that is via front matter and _index.md as described earlier (with a type parameter defined in it).

I did see the use of output types being used for template resolution. I will look further into this to see if that is what I am looking for here. Thank you for the link. :+1:

@regis you are my hero! Very nice lead here. It took me a while to grok the output types but I was able to make it work.

To start, after more research, I determined that what I was looking for was nested/subsection templates, which is not available.

So what I did was configure my config.yaml:

outputFormats:
  Details:
    path: details
    mediaType: text/html
outputs:
  taxonomy:
  - HTML
  - DETAILS
  - RSS

And then create a /layouts/authors/author.details.html

Boom. I now have /authors//detail/ created for all authors! However, at this point, all taxonomy terms have a detail. No matter, I then created a /taxonomy/taxonomy.details.html which simply includes my 404 message, which I also extracted to a partial. :nerd_face:

(pardon my French here)

Much appreciated! Very clever trick to keep around while developing with this amazing tech. :+1:

1 Like

That’s great to hear!

I love reading about a good output format use case :slight_smile:

See you around!