Content of /tricks/ section is open-source.
You're welcome to:
Content of /tricks/ section is open-source.
You're welcome to:
This is a huge advantage for .liquid over .njk so far.
{% # prettier-ignore %} might not help with that, because the parser crashes on the "broken" HTML before it even reads the ignore command.
But there is a trick with "fake" {% if true %} condition:
{% if true %}<html>{% endif %}
<head>
...
</head>
{% if true %}<body>{% endif %}
...
{% if true %}</body><html>{% endif %}
This "fake conditional" trick is a clever way to bypass the Abstract Syntax Tree (AST) parsers used by formatters like Prettier. Since the formatter sees the tag wrapped in a logic block, it often treats the HTML as a string or a partial fragment rather than a structural error.
{% capture _new_array %}
1
2
3
{% endcapture %}
{% assign _new_array = _new_array | strip | split: '\n' %}
.liquid ❌ Wrong:
{% if my_string %} This will always show if the string exists, even if empty. {% endif %}
✅ Right (Checking for content):
{% if my_string != blank %} This only shows if there is actual text. {% endif %}
✅ Right (Checking arrays/strings by size):
{% if my_array.size > 0 %} This ensures the list isn't empty. {% endif %}
.njk & .liquid) The package includes reusable templates in the ./src/bricks/ directory. These are useful for common web development patterns.
npm install @anydigital/bricks
cd ./src/_includes
ln -s ../../node_modules/@anydigital/bricks/src/bricks
__html.*) A unified base HTML template bricks/__html.{njk|liquid} that provides the essential document structure with built-in support for modern web best practices.
Usage:
{% extends 'bricks/__html.njk' %}
{% block body %}
<!-- YOUR page content -->
{% endblock %}
Example: /anydigital/sveleven/blob/main/src/_theme/__layout.njk
{% capture body %}
<!-- YOUR page content -->
{% endcapture %}
{% include 'bricks/__html' %}
Example: /anydigital/sveleven/blob/main/src/_theme/__layout.liquid
Features:
en, configurable via site.lang)viewport-fit=cover for notched devices|)/favicon.ico)site.styles arraysite.inline_styles array (joined with newlines in a <style> tag)site.scripts array (with defer attribute)site.inline_scripts array (joined with newlines in a <script type="module"> tag)content_for_header_gtm.{njk|liquid} template for both <head> and <body> when site.prod and site.gtm_id are set)Variables:
body - The page content to be rendered inside the <body> tag (required)title - Page title (optional, will be stripped of HTML tags)site.title - Site title for the title suffixsite.lang - Language code (optional, defaults to 'en')site.styles - Array of stylesheet URLs (optional)site.inline_styles - Array of inline CSS strings (optional)site.scripts - Array of script URLs (optional)site.inline_scripts - Array of inline JavaScript strings (optional)content_for_header - Custom HTML for the head section (optional)site.gtm_id - Google Tag Manager ID (optional)site.prod - Boolean flag for production environment (optional)_nav.*) A navigation template bricks/_nav.{njk|liquid} that renders a list of navigation links with proper accessibility attributes.
Parameters:
nav_pages - Array of navigation page objects with url and title propertiescurrent_url - The URL of the current page (used to set aria-current="page")Usage example with Eleventy Navigation plugin:
{% assign nav_pages = collections.all | eleventyNavigation %}
{% render 'bricks/_nav', nav_pages: nav_pages, current_url: page.url %}
Output:
<nav>
<a href="/">Home</a>
<a href="/about" aria-current="page">About</a>
<a href="/contact">Contact</a>
</nav>
_gtm.*) A template bricks/_gtm.{njk|liquid} for embedding Google Tag Manager scripts in your pages.
Parameters:
site.gtm_id - Your Google Tag Manager container ID (e.g., GTM-XXXXXXX)site.prod - Boolean flag to enable GTM only in productionfor_body - Boolean flag (default: false). When false, renders the script tag for the <head>. When true, renders the noscript fallback for the <body>.Note: This template is automatically included when using __html.liquid. You only need to manually render it if you're not using that base template, see examples:
Featured in:
© 2025–2026