mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-18 20:54:38 -04:00
Update types content
This commit is contained in:
parent
bca33c387a
commit
9c03693dbd
@ -15,13 +15,15 @@ toc: true
|
||||
|
||||
Hugo provides full support for sites with multiple content types. A **content type** can have a unique set of metadata (i.e., [front matter][]) or customized [template][] and can be created by the `hugo new` command via [archetypes][].
|
||||
|
||||
[Tumblr][] is a good example of a website containing multiple content types. A piece of "content" could be a photo, quote, or a post, each with different sets of metadata and different visual rendering.
|
||||
## What is a Content Type
|
||||
|
||||
[Tumblr][] is a good example of a website with multiple content types. A piece of "content" could be a photo, quote, or a post, each with different sets of metadata and different visual rendering.
|
||||
|
||||
## Assigning a Content Type
|
||||
|
||||
Hugo assumes that your site will be organized into [sections][] and each section will use a corresponding type. This is to reduce the amount of configuration necessary for new Hugo projects.
|
||||
|
||||
If you are taking advantage of this default behavior, each new piece of content you place into a section will automatically inherit the type. Alternatively, you can set the content type in a content file's [front matter][] in the field "`type`".
|
||||
If you are taking advantage of this default behavior, each new piece of content you place into a section will automatically inherit the type. Therefore a new file created at `content/posts/new-post.md` will automatically be assigned the type `posts`. Alternatively, you can set the content type in a content file's [front matter][] in the field "`type`".
|
||||
|
||||
## Creating New Content of a Specific Type
|
||||
|
||||
@ -32,7 +34,7 @@ You can manually add files to your content directories, but Hugo has the ability
|
||||
Creating a new content type is easy in Hugo. You simply define and provide the templates and archetype unique to your new content type. Hugo will fall back to using the general templates and default archetype whenever a specific file is not present.
|
||||
|
||||
{{% note "Declaring Content Types" %}}
|
||||
Remember, all of the following are *optional*. If you do not specifically declare content types in your front matter or develop specific layouts for content types, Hugo is smart enough to assume the content type from the file path and content section. (See [Content Sections](/content-management/sections/) for more information.)
|
||||
Remember, all of the following are *optional*. If you do not specifically declare content types in your front matter or develop specific layouts for content types, Hugo is smart enough to assume the content type from the file path and section. (See [Content Sections](/content-management/sections/) for more information.)
|
||||
{{% /note %}}
|
||||
|
||||
The following examples take you stepwise through creating a new type layout for a content file that contains the following front matter:
|
||||
@ -53,16 +55,16 @@ By default, Hugo assumes `*.md` under `events` is of the `events` content type.
|
||||
|
||||
### Create a Type Layout Directory
|
||||
|
||||
Create a directory with the name of the type in `/layouts`. **Type is always singular**; e.g., `events => event` and `posts => post`.
|
||||
Create a directory with the name of the type in `/layouts`. For creating these custom layouts, **type is always singular**; e.g., `events => event` and `posts => post`.
|
||||
|
||||
For the above example, you would create a layout directory at `layouts/event/birthday.html`.
|
||||
For this example, you need to create `layouts/event/birthday.html`.
|
||||
|
||||
{{% note %}}
|
||||
If you have multiple content files in your `events` directory that are of the `special` type and you don't want to define the `layout` specifically for each individual, you can create a layout at `layouts/special/single.html` to observe the [single page template lookup order](/templates/single-page-templates/).
|
||||
If you have multiple content files in your `events` directory that are of the `special` type and you don't want to define the `layout` specifically for each piece of content, you can create a layout at `layouts/special/single.html` to observe the [single page template lookup order](/templates/single-page-templates/).
|
||||
{{% /note %}}
|
||||
|
||||
{{% warning %}}
|
||||
With the "everything is a page" data model introduced in v0.18 (see [Content Organization](/content-management/organization/)), you can use `_index.md` in content directories to add both content and front matter to [section templates](/templates/section-templates). However, `type` and `layout` declared in the front matter of `_index.md` are *not* currently respected at build time as of v0.19. This is a known issue [(#3005)](https://github.com/spf13/hugo/issues/3005).
|
||||
With the "everything is a page" data model introduced in v0.18 (see [Content Organization](/content-management/organization/)), you can use `_index.md` in content directories to add both content and front matter to [list pages](/templates/lists/). However, `type` and `layout` declared in the front matter of `_index.md` are *not* currently respected at build time as of v0.19. This is a known issue [(#3005)](https://github.com/spf13/hugo/issues/3005).
|
||||
{{% /warning %}}
|
||||
|
||||
### Create Views
|
||||
|
Loading…
x
Reference in New Issue
Block a user