Hash Filters
Hash filters generate cryptographic hash values from strings. These are useful for cache busting, generating unique identifiers, or integrating with services that require hashed values.
Generates an MD5 hash of the input string.
Syntax:
{{ string | md5 }}Output: A 32-character hexadecimal string.
{{ "hello@example.com" | md5 }}{{ "Hello World" | md5 }}b642b4217b34b1e8d3bd915fc65c4452b10a8db164e0754105b7a99be72e3fe5Example Usage
Section titled “Example Usage”Gravatar images:
{% assign email_hash = user.email | downcase | md5 %}<img src="https://www.gravatar.com/avatar/{{ email_hash }}?s=200&d=mp" alt="{{ user.name }}">Cache busting:
{% assign cache_key = page.updatedAt | md5 %}<link href="{{ 'css/main.css' | asset_url }}&h={{ cache_key }}" rel="stylesheet">Generates a SHA-1 hash of the input string.
Syntax:
{{ string | sha1 }}Output: A 40-character hexadecimal string.
{{ "hello@example.com" | sha1 }}{{ "Hello World" | sha1 }}4e7a943fbbe5af5cc77216f5614900aeb3d32b580a4d55a8d778e5022fab701977c5d840bbc486d0Example Usage
Section titled “Example Usage”Generating unique IDs:
{% assign unique_id = block.id | append: now | sha1 | slice: 0, 8 %}<div id="section-{{ unique_id }}"> ...</div>