Hugo _index.md function
#_index.md
Hugo _index.md
In Hugo, the _index.md file plays a crucial role in organizing and displaying content for sections, taxonomies, and terms. Here are some key points about using _index.md:
-
Location and Purpose: An
_index.mdfile is used to add content and front matter to home, section, taxonomy, and term pages. It should be placed in the relevant directory within thecontentfolder. For example, to add content and front matter to the home page, you would place_index.mdin the top-levelcontentdirectory. -
Rendering: The content and front matter in
_index.mdare rendered by specific templates. For instance, the home page might uselayouts/index.html, while section pages use templates likelayouts/section/post.html. -
Structure and Nesting: Sections can be nested as deeply as needed. However, to ensure full navigability, the lowest-level section must include a content file, typically named
_index.md. -
Content Type and Layouts: The top-level folders in the
contentdirectory are special in Hugo and determine the content type and associated layouts. For example,content/posts/_index.mdandcontent/categories/_index.mdare used to manage posts and categories, respectively. -
Content Management: If you need to use a different file name for the homepage content, such as
intro.md, you can use Hugo’sGetPagefunction in your template to render the content from that file. For example:{{- (.Site.GetPage "intro").Content -}} -
Page Bundles:
_index.mdfiles are part of branch bundles, which allow for nested content and navigable URLs for subfolders. In contrast, leaf bundles useindex.mdand do not create navigable URLs for sibling pages.