Question about main page

This may be a stupid basic question, but my home page is set by my baseof.html, I’m trying to figure out how to have content on it without setting the other pages (static, list, single) an example is I want the commented code (partials) only to be visible on the main page (home) and no other pages:

<!DOCTYPE html>
<html lang="{{ with site.LanguageCode }}{{ . }}{{ else }}en-us{{ end }}">
    {{ partial "head.html" . }}
    <body>
        {{ partial "navigation.html" . }}
        {{ partial "header_banner.html" . }}
        <!--  start of partials
        {{ partial "mission_banner.html" . }}
        {{ partial "specials_banner.html" . }}
        {{ partial "team.html" . }}
        {{ partial "feature_products.html" . }}
        {{ partial "products_banner.html" . }}
        {{ partial "form_newsletter.html" . }}
        {{ partial "form_consultation.html" . }}
        {{ partial "form_contact.html" . }} 
        end of partials-->
        {{ block "main" .}}

        {{ end }}
        {{ partial "contact_info.html" . }}
        {{ partial "tool-top.html" . }}
    </body>
    {{ partial "footer.html" . }}
</html>

You can check if .IsHome: Page Variables | Hugo

{{ if .IsHome }}
  partials 
{{ end }}
2 Likes

Personally, I would just call those partials from layouts/index.html, not layouts/_default/baseof.html.

That way you don’t need any extra logic and your homepage content is defined on your homepage only. Just feels cleaner to me.

My index.html:

{{ define "main" }}
 {{ partial "header__list.html" . }}
 {{ partial "features.html" . }}
 {{ partial "stats.html" . }}
 {{ partial "testimonials.html" . }}
 {{ partial "pricing.html" . }}
 {{ partial "recent_posts.html" . }}
 {{ partial "clients.html" . }}
{{ end }}

To my mind, the default layout is just that, it should not contain the ‘content’ of any page, that’s what page templates and content directories are for.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.