The template data object

The major responsibility of the template data object (or simply the data object) is to supply a given template with data that is to be presented to the user. In the About page that we will be constructing, there are two pieces of data that need to be presented. The first need is subtle, it's the title of the web page that will be displayed in the web browser's title bar window, or as the title of the web browser tab containing the web page. The second data need is more profound, it is the data object, the list of gophers that should be displayed on the About page.

We will use the following About struct from the templatedata package, defined in the shared/templatedata/about.go source file, to fulfill the data needs of the About page:

type About struct {
PageTitle string
Gophers []*models.Gopher
}

The PageTitle field represents the web page title that should be displayed in the web browser's title bar (or as the title of the web browser tab). The Gophers field is a slice of pointers to a Gopher struct. The Gopher struct represents a gopher, a member of the IGWEB team, that should be displayed on the About page.

The definition for the Gopher struct can be found in the gopher.go source file found in the shared/models folder:

type Gopher struct {
Name string
Title string
Biodata string
ImageURI string
StartTime time.Time
}

The Name field represents the name of the Gopher. The Title field represents the title that the IGWEB organization has bestowed to a particular gopher. The Biodata field represents a brief bio about a particular gopher. We used a loren ipsum generator, to generate some random gibberish in Latin, to populate this field. The ImageURI field is the path to the image of the gopher that should be displayed, relative to the server root. The gopher's image will be displayed on the left-hand side of the page, and the the gopher's profile information will be displayed on the right-hand side of the page.

Finally, the StartTime field represents the date and time that the gopher joined the IGWEB organization. We will be displaying the gopher's start time in the standard time format, and later in this chapter we will learn how to display the start time using Ruby-style formatting by implementing a custom template function. In Chapter 9, Cogs – Reusable Components, we will learn how to display the start time in the human readable time format.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.220.83