Skip to main content
Snippets are reusable pieces of code that can be included in templates, sections, and other snippets. Horizon includes 93 snippets for various functionality.

Overview

Snippets help maintain DRY (Don’t Repeat Yourself) code principles by centralizing common functionality. They can be included using the render tag:
Total Snippets: 93

Snippet Categories

Using Snippets

Basic Usage

With Multiple Parameters

Assigning Variables

Snippet Best Practices

Do:
  • Pass parameters explicitly for clarity
  • Keep snippets focused on a single responsibility
  • Document expected parameters in comments
  • Use semantic naming for snippet files
Don’t:
  • Access global variables when parameters can be passed
  • Create deeply nested snippet renders (max 3 levels)
  • Mix presentation and logic in the same snippet
  • Forget to handle missing or nil parameters

Common Snippet Patterns

Conditional Rendering

Loop Rendering

Default Parameters

Performance Considerations

Snippets are processed on each render. For frequently used snippets:
  • Cache rendered output when possible
  • Minimize database queries within snippets
  • Use the {% liquid %} tag for better performance
  • Consider using sections for heavy components

Sections Reference

Sections that use snippets

Blocks Reference

Blocks that render snippets