Advanced Template Patterns: Loops, Includes, and Dynamic Configs
Go beyond simple platform checks. Learn advanced template patterns for Apple Silicon detection, tag-based feature flags, profile-driven configs, and managing work and personal settings in one file.
Why Templates Matter
Basic ConfigSync templates let you check the platform with {{platform}} and the hostname with {{hostname}}. These cover simple cases. But real development environments are more nuanced. Apple Silicon Macs need different paths than Intel Macs. GPU workstations need CUDA configuration that laptops should skip. Work and personal machines share 90% of a config but differ in important ways.
This guide covers the template patterns that handle these complex scenarios cleanly.
Pattern: OS + Architecture Combos
Apple Silicon changed the game for macOS development. Homebrew installs to /opt/homebrew on ARM64 but /usr/local on Intel. Nest conditionals to handle each combination:
These conditionals resolve at pull time. The same template file produces the correct output on every machine regardless of its architecture.
Pattern: Tag-Based Feature Flags
Machine tags let you flag capabilities that are not tied to OS or hostname. A GPU workstation, a machine with Docker installed, a high-memory build server:
Pattern: Profile-Driven Variables
Instead of branching on profile names in every config file, define variables that each profile fills differently:
Variables keep your config files readable. Instead of {{#if profile == "work"}} scattered everywhere, you reference a variable and let the profile system fill in the value.
Pattern: Work vs Personal in One File
Sometimes you need different sections rather than different values. Use profile conditionals for the parts that differ, and keep shared configuration outside any conditional:
Tips for Maintainable Templates
First, comment every conditional block. A comment like # Apple Silicon Macsaves you from deciphering nested conditions later.
Second, prefer variables over conditionals when the only difference is a single value. If work and personal differ only in an email address, use {{vars.email}} instead of a five-line conditional block.
Third, keep nesting to two levels maximum. If you need three levels of conditionals, consider splitting the file into platform-specific versions or using tags to flatten the logic.
Finally, test templates before pushing. Run configsync diff to preview what a template will produce on the current machine before committing to the change across all your devices.
Ready to try ConfigSync?
Sync your entire dev environment across machines in minutes. Free forever for up to 3 devices.