If `list`, do this. if `single` do that

Hello, I am wondering if I can use conditional if statement logic based on the type of file the partial is being included from.

For example, if both my List and Single layouts ingest partial sidebar, can I have logic in the sidebar partial to display slightly modified information?

1 Like

oh I think I found my answer - https://codeandsend.com/blog/how-to-identify-single-pages-in-hugo/

That post says:

Hugo doesn’t have {{ if .IsSinglePage }} so it’s not such a trivial task to detect single post pages.

It was written a while ago, so maybe it didn’t exist back then, but we do have .IsPage. That will probably help ya. :slight_smile:

Thank you @maiki. I tried that along with the solution in the post, but neither work exactly like what I need. I am using the same img.html partial for both my list item images and my hero images in my single pages.

Adding the .isPage does indeed add lorem ipsum to the single pages, but I also see it on my list page as a part of my summary partial (which consumes the img.html partial).

Sounds like you are close to figuring it out. Now that you know you can figure out if the output is a page, you can step back and see if the partial can be refactored.

I suggest also looking at .Kind:

Possible return values are page, home, section, taxonomy, or taxonomyTerm.