Legal Markdown JS supports multiple syntaxes for conditional content based on YAML variables. Each syntax offers different advantages for various use cases.
- Supported Syntaxes
- Modern Bracket Syntax
- Block Conditional Syntax
- Simple Variable Syntax
- Legacy Bracket Syntax
- Operators and Expressions
- Advanced Use Cases
- Template Loops
- Best Practices
Legal Markdown JS supports 4 different syntaxes for generating optional clauses, each with its own advantages and specific use cases:
| Syntax | Format | Advantages | Use Cases |
|---|---|---|---|
| Modern brackets | [content]{condition} |
Compact, natural | Inline text, expressions |
| Conditional {{#if}} | {{#if condition}}content{{/if}} |
More readable, else support | Complex conditions |
| Simple {{#variable}} | {{#variable}}content{{/variable}} |
Concise, automatic loops | Simple boolean variables |
| Legacy brackets | [{{condition}}content] |
Legacy compatible | Migration from previous versions |
The recommended syntax for inline conditional content:
[This clause appears only if confidentiality is required.]{confidentiality}
[Premium support is included for enterprise clients.]{client.type ==
"enterprise"}
[This applies to California residents only.]{jurisdiction == "California"}
The service [includes priority support]{isPremium} and [24/7
availability]{hasExtendedSupport}.[Special terms will apply]{premium && region == "EU"} according to European
legislation.
[A {{discountPercent}}% discount will be applied]{amount >= 1000}
[Volume discount applies]{quantity >= 100} for large orders.Services include: basic consulting[, phone support]{hasPhoneSupport}[, and
access to premium resources]{isPremiumClient}.Required metadata:
hasPhoneSupport: true
isPremiumClient: falseResult:
Services include: basic consulting, phone support.
For complex conditions with logical operators and optional else clauses:
{{#if premium && region == "US"}} **Premium US Terms:**
- 24/7 phone support
- Priority handling
- Extended warranty
{{else}} **Standard Terms:**
- Email support
- Standard processing
- Basic warranty {{/if}}{{#if client.type == "enterprise"}} {{#if client.region == "US"}} Special US
enterprise terms apply. {{else}} International enterprise terms apply. {{/if}}
{{/if}}{{#if (premium || enterprise) && status == "active"}} Advanced features are
available for your account type. {{/if}}
{{#if premium && status == "active" && region == "US"}} Special terms for active
premium users in the United States. {{/if}}Concise syntax for boolean variables and automatic array iteration:
{{#includeWarranty}} **Warranty Terms:** This product includes a 12-month
warranty covering defects. {{/includeWarranty}}
{{#includeStandardTerms}} l. **Standard Terms**
The company's standard terms and conditions apply. {{/includeStandardTerms}}The system automatically detects arrays and iterates over them:
{{#services}}
- {{name}}: {{formatCurrency(price, currency)}} {{/services}}Required metadata:
services:
- name: 'Legal Consulting'
price: 150
currency: 'USD'
- name: 'Contract Review'
price: 200
currency: 'USD'Result:
- Legal Consulting: $150.00
- Contract Review: $200.00
{{#client_has_premium}} ll. **Premium Services**
As a premium client, you have access to:
- Priority support
- Advanced features
- Exclusive discounts {{/client_has_premium}}For compatibility with legacy document syntax:
[{{confidentiality}}This information is confidential and proprietary.]
[{{showLegalNotice}}This document is legally binding and has been reviewed by
certified attorneys.]
[{{client_has_warranty}}Warranty terms apply as described in Appendix A.][{{includeDetails}}For more information, see Section 5.2 of this document.]Note: For detailed information about comparison and boolean operators, including complex expressions and best practices, see the Conditionals documentation.
| Operator | Description | Example |
|---|---|---|
== |
Equal to | status == "active" |
!= |
Not equal to | type != "trial" |
> |
Greater than | amount > 1000 |
< |
Less than | users < 50 |
>= |
Greater than or equal | score >= 80 |
<= |
Less than or equal | age <= 65 |
| Operator | Description | Example |
|---|---|---|
&& |
Logical AND | premium && active |
|| |
Logical OR | trial || premium |
{{#if premium && status == "active" && region == "US"}} Special terms for active
premium users in the United States. {{/if}}[Discount applicable]{isStudent || isSenior || isVeteran}{{#if (premium || enterprise) && status == "active"}} Access to advanced
features enabled. {{/if}}[Volume discount applies]{quantity >= 100} for large orders.
{{#if amount > 10000}} Executive approval required for high-value contracts.
{{/if}}You can use different syntaxes in the same document:
l. **Terms and Conditions**
{{#if premium}} ll. **Premium Features** Premium users have access to advanced
features. {{/if}}
{{#standardWarranty}} ll. **Warranty** Standard warranty terms apply.
{{/standardWarranty}}
ll. **Additional Terms** [See Appendix A]{hasAppendix} for additional terms.
[{{showLegalNotice}}This document is legally binding.]{{#if client.subscription.isPremium}} **Premium Client Detected**
- Level: {{client.subscription.level}}
- Valid until: {{client.subscription.expiryDate}} {{/if}}Required metadata:
client:
subscription:
isPremium: true
level: 'Gold'
expiryDate: '2024-12-31'[A {{discountPercent}}% discount will be applied]{amount >= 1000}Required metadata:
amount: 1500
discountPercent: 15{{#items}} l. {{name}} - ${{price}} {{description}} {{/items}}Within loops, special variables are available:
| Variable | Description | Example |
|---|---|---|
@index |
Current index (0-based) | Item #{{@index}} |
@first |
Is the first element | {{#if @first}}First item{{/if}} |
@last |
Is the last element | {{#if @last}}Last item{{/if}} |
@total |
Total number of elements | {{@index}} of {{@total}} |
**Service List:**
{{#services}} {{@index + 1}}. **{{name}}** - {{formatCurrency(price, currency)}}
{{description}} {{#if @last}}
_All prices include taxes_ {{/if}} {{/services}}Required metadata:
services:
- name: 'Legal Consulting'
price: 150
currency: 'USD'
description: 'General legal advice'
- name: 'Contract Review'
price: 200
currency: 'USD'
description: 'Detailed analysis of contractual documents'{{#departments}} l. **{{name}}**
{{#employees}}
- {{name}} ({{position}}) {{/employees}} {{/departments}}Use {{#if condition}} when:
- You need complex logic with operators
- You require an
elseclause - The condition is long or complex
Use {{#variable}} when:
- Working with simple boolean variables
- You need automatic loops over arrays
- You want concise syntax
Use [content]{condition} when:
- The content is inline text
- You need multiple conditions in a paragraph
- You prefer compact syntax
Use [{{condition}}content] when:
- Migrating from previous versions of Legal Markdown
- Supporting legacy document formats
# Group related variables
client:
isPremium: true
hasSupport: true
region: 'US'
terms:
includeWarranty: true
includeStandardTerms: false
showLegalNotice: true
services:
- name: 'Service A'
price: 100
- name: 'Service B'
price: 200# ✅ Good - descriptive names
{{#if includeWarrantyClause}}
# ❌ Bad - generic names
{{#if flag1}}# Optional clauses configuration
includeWarrantyClause: true # Show warranty terms
showPremiumFeatures: false # Hide premium features
clientRegion: 'EU' # Determines applicable legislationInvalid conditions or non-existent variables fail safely:
- False conditions or non-existent objects don't show content
- Malformed conditions include content by default (safe behavior)
- Missing variables show as unprocessed
{{variable}}
Always verify that your conditions work correctly:
# Use debug mode to see condition evaluation
legal-md document.md --debug{{#if includeReferences}} For more details, see |terms| and |conditions|.
{{/if}}{{#if showDate}} Effective date: {{formatDate @today "MMMM Do, YYYY"}} {{/if}}{{#if includeSection}} l. Conditional Section
This content only appears when includeSection is true. {{/if}}---
confidentiality_required: true
warranty_included: true
jurisdiction: 'California'
client_type: 'enterprise'
---
{{#if confidentiality_required}} l. **Confidentiality**
All information shared under this agreement is confidential. {{/if}}
{{#if warranty_included}} l. **Warranty**
[Extended warranty applies]{client_type == "enterprise"} to this agreement.
{{/if}}
[California law applies]{jurisdiction == "California"} to this agreement.---
service_level: 'premium'
support_24x7: true
region: 'US'
---
l. **Service Level**
You will receive {{service_level}} service[, including 24/7
support]{support_24x7}.
{{#if service_level == "premium" && region == "US"}} ll. **Premium US Benefits**
- Priority phone support
- Dedicated account manager
- Same-day response guarantee {{/if}}- Conditionals - Complete guide to conditional expressions and operators
- YAML Frontmatter - Defining variables for conditions
- Variables & Mixins - Using variables in content
- Cross-References - Using references in conditional content