Template Helpers
Barry provides multiple template helper functions
versioned
The versioned
template function appends a hash based on file content to the URL for automatic cache-busting. This applies to files in /static/
.
<img src="{{ "/static/image.jpg" | versioned }}">
This outputs something like: /static/image.jpg?v=5c1b23
Note: Only works on files in /static/
that exist on disk. Returns original path if not found.
minify
The minify
template function lets you minify CSS and JavaScript assets directly from your templates using a built-in template function. This helps reduce file size, enable compression, and bust stale caches automatically.
This only applies to .css
and .js
files inside /static/
. Files ending in .min.css
or .min.js
are skipped. Minified output is saved to /cache/static/
and served with gzip compression and a cache-busting hash.
See Asset Minification for more information.
safeHTML
The safeHTML
template function allows you to safely render raw HTML inside your templates. Use it when you’re injecting HTML content from a server file and want to prevent it from being escaped.
<div>{{ safeHTML .Content }}</div>
This is useful for pre-formatted HTML strings (e.g. from Markdown rendering). Use with caution to avoid XSS vulnerabilities. Only use on trusted content.