HTML Templates
Go’s templating library (html/template
) is used to generate the front-end interface. All the templates can be found in /res/templates
in the main repository.
Structure:
page.tmpl
is the base/foundation of every page.head.tmpl
contains information for the head of each page. This remains consistent for all pages, apart from a few things such as the<title>
.body/
contains the body content templates for each page, such as the login or the timetable.components/
has the rest of the reusable content such as the navbar and footer.
If you add a new template file, you must also add that file to the tmplFiles
array in func initTemplates
, which is situated in server.go
in the server
package. This is required as TaskCollect uses it to ensure that the template files are not missing upon first running it. This is necessary as html/template
does not check which template files would be necessary when the user visits the web pages. Even if template files are missing, html/template
will not raise any errors when loading template files. An error will only be raised when a user tries to visit a page which utilises that template.
The template file list (tmplFiles
) looks something like the following:
tmplFiles := []string{
"page", "head",
"components/header", "components/nav", "components/footer",
"body/error", "body/login", "body/main",
"body/grades", "body/resource", "body/resources",
"body/task", "body/tasks", "body/timetable",
}
You must update the template file list, or else the TaskCollect will be unable to determine if template files are missing before starting the server.
Please do not add any directories to /res/templates
unless there is an absolute need to do so. As it stands, body/
and components/
should suffice. If there is still such a need, raise this concern using appropriate communication channels (email, IRC).