Here’s a step-by-step guide to creating a Hugo theme and integrating a fabform.io contact form:
1. Create a Hugo Site and Theme
Step 1: Install Hugo
Ensure Hugo is installed on your system. Follow Hugo's installation guide.
Step 2: Create a New Hugo Site
hugo new site my-hugo-site
cd my-hugo-site
Step 3: Create a New Theme
hugo new theme my-theme
This creates a basic theme in the themes/my-theme
directory.
Step 4: Apply the Theme
Edit the config.toml
file to use your new theme:
theme = "my-theme"
2. Design the Theme Layout
Step 1: Set up a basic structure
Inside the themes/my-theme/layouts
directory, create the following files:
-
layouts/_default/baseof.html
: Base template. -
layouts/_default/single.html
: Template for single pages.
Example for baseof.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ .Title }}</title>
</head>
<body>
{{ block "main" . }}{{ end }}
</body>
</html>
Example for single.html
:
{{ define "main" }}
<main>
<h1>{{ .Title }}</h1>
{{ .Content }}
</main>
{{ end }}
3. Add the Fabform.io Contact Form
Step 1: Create a Contact Page
Generate a new contact page:
hugo new contact.md
Edit the content/contact.md
file:
---
title: "Contact"
---
<form action="https://fabform.io/f/YOUR_FORM_ID" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="message">Message:</label>
<textarea id="message" name="message" required></textarea>
<button type="submit">Send</button>
</form>
Step 2: Style the Form
Add custom CSS in the themes/my-theme/static/css/style.css
file and link it in baseof.html
:
<link rel="stylesheet" href="/css/style.css">
Example CSS:
form {
display: flex;
flex-direction: column;
max-width: 400px;
margin: 0 auto;
}
label, input, textarea, button {
margin-bottom: 10px;
}
button {
padding: 10px;
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
4. Test and Deploy
Step 1: Run Locally
hugo server
Visit http://localhost:1313/contact/
to test the contact form.
Step 2: Deploy
Build the site:
hugo
Deploy the public
directory to your preferred hosting platform.
That's it! Your Hugo theme is ready with a functional Fabform.io contact form.
Top comments (0)