Welcome to mirror list, hosted at ThFree Co, Russian Federation.

types.md « content « content « docs - github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 563e6f7cbfda6cbd0f80e52e6e758a606e1fe550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: "Content Types"
date: "2013-07-01"
linktitle: "Types"
menu:
    main:
        parent: 'content'
weight: 40
prev: '/content/sections'
next: '/content/archetypes'
---

Hugo has full support for different types of content. A content type can have a
unique set of meta data, template and can be automatically created by the new
command through using content [archetypes](/content/archetypes).

A good example of when multiple types are needed is to look at Tumblr. A piece
of content could be a photo, quote or post, each with different meta data and
rendered differently.

## Assigning a content type

Hugo assumes that your site will be organized into [sections](/content/sections)
and each section will use the corresponding type. If you are taking advantage of
this then each new piece of content you place into a section will automatically
inherit the type.

Alternatively you can set the type in the meta data under the key "type".


## Creating new content of a specific type

Hugo has the ability to create a new content file and populate the front matter
with the data set corresponding to that type. Hugo does this by utilizing
[archetypes](/content/archetypes).

To create a new piece of content use:

    hugo new relative/path/to/content.md

For example if I wanted to create a new post inside the post section I would type:

    hugo new post/my-newest-post.md


## Defining a content type

Creating a new content type is easy in Hugo. You simply provide the templates and archetype
that the new type will use. You only need to define the templates, archetypes and/or views
unique to that content type. Hugo will fall back to using the general templates and default archetype
whenever a specific file is not present.

*Remember, all of the following are optional:*

### Create Type Directory
Create a directory with the name of the type in layouts.Type is always singular.  *Eg /layouts/post*.

### Create single template
Create a file called single.html inside your directory. *Eg /layouts/post/single.html*.

### Create list template
Create a file called list.html inside your directory  *Eg /layouts/post/list.html*.

### Create views
Many sites support rendering content in a few different ways, for
instance a single page view and a summary view to be used when displaying a list
of contents on a single page. Hugo makes no assumptions here about how you want
to display your content, and will support as many different views of a content
type as your site requires. All that is required for these additional views is
that a template exists in each layout/type directory with the same name.

### Create a corresponding archetype

Create a file called `type`.md in the /archetypes directory *Eg /archetypes/post.md*.

More details about archetypes can be found at the [archetypes docs](/content/archetypes)