Use Template Helpers

This guide shows how to use Azu's built-in template helpers for common web development tasks.

Prerequisites

Template helpers are automatically available in all templates when using Azu's Renderable module.

Building Forms

Basic Form

{{ form_tag("/users", method="post") }}
  {{ csrf_field() }}
  
  {{ label_tag("user_name", "Name") }}
  {{ text_field("user", "name", required=true) }}
  
  {{ label_tag("user_email", "Email") }}
  {{ email_field("user", "email", required=true) }}
  
  {{ submit_button("Create User") }}
{{ end_form() }}

This generates proper name attributes like user[name] and user[email], which work with Azu's params parsing.

Form with File Upload

Form with Validation Styles

Select Dropdown

Checkbox and Radio Buttons

Basic Navigation

With Conditional Active Class

Delete Buttons with Confirmation

Using Type-Safe Endpoint Helpers

When you define endpoints in Crystal, Azu automatically generates type-safe helpers with the HTTP method in the name. This makes it clear what action each helper performs.

Form Helpers for Endpoints

Delete Buttons with Endpoint Helpers

Complete CRUD Example

Working with Assets

Page Head Section

Scripts at End of Body

Responsive Images

Internationalization

Setup Locale Files

Create YAML files in your locales directory:

Using Translations

Formatting Dates

Language Switcher

Formatting Numbers and Dates

Currency and Numbers

Relative Times

Custom Date Formats

Safe HTML Output

Escaping HTML (Default)

By default, all output is HTML-escaped:

Marking Content as Safe

Only use with trusted content:

Auto-linking URLs

Highlighting Search Terms

Complete Page Example

See Also

Last updated

Was this helpful?