Overview
The FreshJuice theme includes a collection of reusable HubL macros that provide common functionality for template development. These macros are located in thetheme/macros/ directory and can be imported into any template file.
Available Macros
slugify
Converts a string into a URL-friendly slug by removing special characters, converting to lowercase, and replacing spaces with hyphens. Location:theme/macros/slugify.html
Parameters
text(required): String to convert into a slug
Usage
Implementation Details
The macro performs the following transformations:- Converts text to lowercase and strips HTML tags
- Replaces spaces and whitespace characters with hyphens
- Removes all non-alphanumeric characters (except hyphens and underscores)
- Replaces multiple consecutive hyphens with a single hyphen
- Trims hyphens from the start and end of the string
unique_id
Generates a unique identifier by combining multiple random integers. Useful for creating unique IDs for HTML elements. Location:theme/macros/unique-id.html
Parameters
NoneUsage
Implementation Details
The macro generates five random 6-digit numbers and joins them with underscores to create a unique identifier.minutes_to_read
Calculates the estimated reading time for blog post content based on an average reading speed of 300 words per minute. Location:theme/macros/minutes-to-read.html
Parameters
my_content(required): Content object containingpost_bodybefore(optional): HTML/text to display before the number (default:'<span>')after(optional): HTML/text to display after the number (default:'</span>')
Usage
Implementation Details
- Strips HTML tags from the post body and counts words
- Rounds word count to nearest hundred
- Divides by 300 (average words per minute)
- Rounds to whole minutes
- Only displays if reading time is 1 minute or more
random_int
Generates a random 6-digit integer. Used internally byunique_id but can also be used standalone.
Location: theme/macros/random-int.html
Parameters
NoneUsage
Implementation Details
Generates a 6-digit number by randomly selecting digits from 0-9 six times in sequence.Best Practices
Importing Macros
Always import macros at the top of your template file for better organization:Performance Considerations
- Macros are processed server-side during template rendering
random_intandunique_idgenerate different values on each page load- For consistent IDs across page loads, consider using content-based identifiers instead