# Shortcodes Documentation - danix.xyz
The danix.xyz theme provides essential shortcodes for extending and enhancing your content. All shortcodes support multilingual content through Hugo's i18n framework, ensuring seamless language switching across your site.
## Gravatar
Display an avatar from Gravatar based on an email address hash. This shortcode retrieves the user's profile image directly from the Gravatar service, perfect for author bios, team pages, and contributor profiles.
### Syntax
```
{{< gravatar email="user@example.com" >}}
```
### Parameters
| Parameter | Required | Description |
|-----------|----------|-------------|
| email | Yes | Email address for Gravatar lookup |
| size | No | Avatar size in pixels (default: 256). Internally converted to integer for correct Gravatar API formatting. |
| alt | No | Alt text for accessibility (default: "User avatar") |
| class | No | Custom CSS classes (default: "w-32 h-32 rounded-full") |
### Example
Basic usage:
```
{{< gravatar email="danix@danix.xyz" >}}
```
With custom styling:
```
{{< gravatar email="danix@danix.xyz" alt="Danilo Profile" class="w-48 h-48 rounded-full border-4 border-accent" >}}
```
## Image
Display a responsive image with optional caption and automatic lazy-loading. Images are optimized for all screen sizes and support accessibility best practices.
### Syntax
```
{{< image src="/path/to/image.jpg" alt="Description" caption="Optional caption" >}}
```
### Parameters
| Parameter | Required | Description |
|-----------|----------|-------------|
| src | Conditional | Path or URL to the image file (required unless inner content is provided) |
| alt | No | Alt text for accessibility (default: "Image") |
| caption | No | Optional caption displayed below the image |
| class | No | CSS classes for the `` element (default: "w-full h-auto rounded-lg border border-border"). Overrides all defaults when specified. |
| link | No | URL to wrap the image in a clickable link |
| figure-class | No | CSS classes applied to the outer `` element (e.g., for centering or custom layout) |
### Example
Basic usage:
```
{{< image src="/images/mountain.jpg" alt="Mountain landscape" >}}
```
With caption:
```
{{< image src="/images/mountain.jpg" alt="Mountain landscape" caption="Hiking in the Alps" >}}
```
With custom sizing and styling:
```
{{< image src="/images/mountain.jpg" alt="Mountain landscape" class="w-2/3 mx-auto rounded-lg shadow-lg border-2 border-accent" >}}
```
With link:
```
{{< image src="/images/mountain.jpg" alt="Mountain landscape" link="https://github.com/example" caption="Click to view project" >}}
```
Centered image with figure-class:
```
{{< image src="/images/mountain.jpg" alt="Mountain landscape" caption="Alpine view" figure-class="text-center" >}}
```
### Common CSS Classes for Image Sizing
Use Tailwind CSS utility classes to customize image appearance:
#### Width & Layout
| Class | Effect |
|-------|--------|
| `w-full` | Full container width (default) |
| `w-1/2` | 50% width |
| `w-2/3` | 66% width |
| `w-3/4` | 75% width |
| `max-w-lg` | Max 512px width |
| `max-w-2xl` | Max 672px width |
| `max-w-3xl` | Max 768px width |
| `mx-auto` | Center horizontally |
#### Height & Aspect Ratio
| Class | Effect |
|-------|--------|
| `h-auto` | Auto height (maintains aspect ratio) |
| `aspect-video` | 16:9 aspect ratio |
| `aspect-square` | 1:1 aspect ratio |
| `aspect-[3/2]` | 3:2 aspect ratio |
| `object-cover` | Fill container, crop if needed |
| `object-contain` | Fit entire image in container |
#### Borders & Shadows
| Class | Effect |
|-------|--------|
| `rounded-lg` | Large rounded corners (default) |
| `rounded-xl` | Extra large rounded corners |
| `border-2` | 2px border |
| `border-accent` | Accent color border |
| `border-border/50` | Semi-transparent border |
| `shadow-lg` | Large drop shadow |
| `shadow-xl` | Extra large drop shadow |
#### Examples
Thumbnail-sized image:
```
{{< image src="/images/thumb.jpg" alt="Thumbnail" class="w-48 h-48 object-cover rounded-lg" >}}
```
Full-width featured image:
```
{{< image src="/images/feature.jpg" alt="Featured image" class="w-full aspect-video object-cover rounded-xl shadow-xl" >}}
```
Centered half-width with border:
```
{{< image src="/images/centered.jpg" alt="Centered" class="w-1/2 mx-auto rounded-lg border-2 border-accent" >}}
```
Small inline image:
```
{{< image src="/images/small.jpg" alt="Small" class="w-32 h-32 rounded-full object-cover inline-block" >}}
```
## Gallery
Create a responsive image gallery grid with automatic column layout. Gallery content uses markdown image syntax and is automatically styled to create a polished gallery experience.
### Syntax
```
{{< gallery cols="2" >}}



{{< /gallery >}}
```
### Parameters
| Parameter | Required | Description |
|-----------|----------|-------------|
| cols | No | Number of columns (default: 2, responsive on mobile) |
### Example
Three-column gallery:
```
{{< gallery cols="3" >}}



{{< /gallery >}}
```
**Note:** Gallery content should be written in standard markdown image syntax ``. The shortcode automatically applies responsive grid styling, handles image sizing, and ensures accessibility.
## Video
Embed responsive HTML5 video player with support for WebM, MP4, and other web video formats. Videos can be stored in page bundles or served from external URLs.
### Syntax
```
{{< video src="video.webm" width="100%" height="600" controls >}}
```
### Parameters
| Parameter | Required | Description |
|-----------|----------|-------------|
| src | Conditional | Path or URL to the video file (required if `id` is not provided; supports .webm, .mp4, .ogv) |
| id | Conditional | YouTube video ID (required if `src` is not provided; triggers YouTube embed mode) |
| title | No | Descriptive title for accessibility (default: "Video"; used as iframe title attribute) |
| width | No | Video width (default: 100%, can be px or % values; video mode only) |
| height | No | Video height (default: auto; video mode only) |
| class | No | Custom CSS classes for styling |
| autoplay | No | Set to "true" to autoplay (default: false; video mode only) |
| loop | No | Set to "true" for looping playback (default: false; video mode only) |
| muted | No | Set to "true" to mute by default (default: false; video mode only) |
### Example
Basic usage with page bundle video:
```
{{< video src="demo.webm" >}}
```
With custom dimensions:
```
{{< video src="tutorial.webm" width="800" height="600" >}}
```
Autoplay and loop:
```
{{< video src="background.webm" width="100%" autoplay="true" loop="true" muted="true" >}}
```
External video URL:
```
{{< video src="https://example.com/video.mp4" width="100%" >}}
```
YouTube embed (recommended for privacy and performance):
```
{{< video id="dQw4w9WgXcQ" title="Example YouTube video" >}}
```
YouTube with custom sizing:
```
{{< video id="dQw4w9WgXcQ" title="Example YouTube video" class="max-w-2xl mx-auto" >}}
```
### Page Bundle Videos
Videos stored in the same directory as your article's `index.md` are automatically resolved:
```
content/en/articles/my-article/
├── index.md
└── demo.webm ← Reference as src="demo.webm"
```
The template automatically generates the correct URL: `/articles/my-article/demo.webm`
### Browser Compatibility
- **WebM (.webm)**: Chrome, Firefox, Edge
- **MP4 (.mp4)**: All modern browsers (H.264 codec)
- **Ogg Theora (.ogv)**: Firefox, Chrome
## Contact Form
Embed a fully functional contact form with client-side validation, AJAX submission, and multilingual support. The form handles user submissions and displays loading states and error/success messages automatically.
### Syntax
```
{{< contact >}}
```
### Parameters
None - the form is fully self-contained and requires no parameters.
### Example
```markdown
## Get in Touch
Send me a message and I'll respond as soon as possible.
{{< contact >}}
```
### Features
- **Client-side validation**: Required field checking and email format validation
- **Loading state**: Visual feedback during form submission
- **Success/error messages**: Multilingual success and error feedback via i18n
- **Multilingual labels**: All form labels translated for each language
- **AJAX submission**: Non-blocking form submission
- **Accessibility**: ARIA labels, semantic HTML, keyboard navigation
### Backend Implementation
To make the contact form functional, implement backend logic in `static/contact.php`:
#### Expected Request
The form sends POST requests to `/contact.php` with the following data:
```json
{
"name": "User Name",
"email": "user@example.com",
"subject": "Message Subject",
"message": "Message content"
}
```
#### Successful Response
Return a JSON response with HTTP 200:
```json
{
"success": true,
"message": "Thank you for your message. I'll get back to you soon."
}
```
#### Error Response
Return a JSON response with appropriate HTTP status code:
```json
{
"success": false,
"error": "An error occurred while sending your message."
}
```
#### Example Implementation (PHP)
```php
false, 'error' => 'Method not allowed']);
exit;
}
$data = json_decode(file_get_contents('php://input'), true);
// Validate input
if (empty($data['name']) || empty($data['email']) || empty($data['message'])) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Missing required fields']);
exit;
}
// Sanitize and validate email
$email = filter_var($data['email'], FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Invalid email address']);
exit;
}
// Send email or save to database
$to = 'contact@danix.xyz';
$subject = htmlspecialchars($data['subject'] ?? 'New Contact Form Submission');
$message = "Name: " . htmlspecialchars($data['name']) . "\n";
$message .= "Email: " . htmlspecialchars($email) . "\n";
$message .= "Message:\n" . htmlspecialchars($data['message']);
if (mail($to, $subject, $message)) {
echo json_encode(['success' => true, 'message' => 'Message sent successfully']);
} else {
http_response_code(500);
echo json_encode(['success' => false, 'error' => 'Failed to send message']);
}
?>
```
## Quote
Display blockquote with optional attribution. Perfect for testimonials, quotes, and highlighted text.
### Syntax
```
{{< quote source="Author Name" src="https://example.com" >}}
Your quote text here
{{< /quote >}}
```
### Parameters
| Parameter | Required | Description |
|-----------|----------|-------------|
| source | No | Author or source attribution |
| src | No | URL to link the source (requires source parameter) |
### Example
Basic quote:
```
{{< quote source="Maya Angelou" >}}
There is no greater agony than bearing an untold story inside you.
{{< /quote >}}
```
With source link:
```
{{< quote source="Steve Jobs" src="https://en.wikipedia.org/wiki/Steve_Jobs" >}}
The only way to do great work is to love what you do.
{{< /quote >}}
```
## Actions
Display a styled action button, typically used for downloads or calls-to-action.
### Syntax
```
{{< actions url="https://example.com/file.zip" desc="Download File" >}}
```
### Parameters
| Parameter | Required | Description |
|-----------|----------|-------------|
| url | Yes | URL the button links to |
| desc | No | Button label text (default: "Download") |
| outclass | No | CSS classes for the wrapper div |
| inclass | No | CSS classes for the anchor link element |
### Example
Basic download button:
```
{{< actions url="https://github.com/user/project/archive.zip" desc="Download ZIP" >}}
```
Centered button:
```
{{< actions url="https://example.com/file.zip" desc="Download" outclass="flex justify-center" >}}
```
Right-aligned button:
```
{{< actions url="https://example.com/file.zip" desc="Download" outclass="flex justify-end" >}}
```
Extra vertical spacing:
```
{{< actions url="https://example.com/file.zip" desc="Download" outclass="my-10" >}}
```
Centered with extra spacing:
```
{{< actions url="https://example.com/file.zip" desc="Download" outclass="flex justify-center my-10" >}}
```
### Common `outclass` Values (wrapper `