Problem
Currently, displaying boolean values in templates requires verbose conditional blocks:
{{#if IsCompleted}}
☑ Completed
{{else}}
☐ Not completed
{{/if}}
For simple checkbox/boolean display, this is unnecessarily complex. Users want a simpler syntax for common boolean display patterns.
Proposed Solution
Add format specifier support to placeholders using the syntax: {{VariableName:format}}
Examples
{{IsCompleted:checkbox}} → ☑ or ☐
{{IsApproved:checkmark}} → ✓ or ✗
{{IsActive:yesno}} → Yes or No
{{IsEnabled:onoff}} → On or Off
{{IsActive:truefalse}} → True or False
{{IsEnabled:enabled}} → Enabled or Disabled
Benefits
- Simpler syntax: One line instead of 4-line if/else block
- More readable: Clear intent in template
- Consistent formatting: Standardized checkbox/boolean display
- Extensible: Can add more formatters (dates, numbers, etc.)
Implementation Considerations
1. Built-in Formatters (English)
Default formatters available out-of-the-box:
:checkbox → ☑ / ☐
:checkmark → ✓ / ✗
:yesno → Yes / No
:truefalse → True / False
:onoff → On / Off
:enabled → Enabled / Disabled
:active → Active / Inactive
2. Internationalization Support
Option A: Culture-Aware Formatting
var options = new DocumentProcessorOptions
{
Culture = new CultureInfo("de-DE")
};
// {{IsActive:yesno}} → Ja / Nein (German)
Option B: Custom Formatter Registration
var options = new DocumentProcessorOptions
{
BooleanFormatters = new Dictionary<string, BooleanFormatter>
{
["yesno"] = new BooleanFormatter("Ja", "Nein"), // German
["ouin"] = new BooleanFormatter("Oui", "Non"), // French
}
};
3. Technical Design
Syntax Parsing:
- Parse
{{VariableName:format}} in placeholder detection
- Extract variable name and format specifier
- Pass format to value converter
Value Conversion:
- Extend
ValueConverter.ConvertToString() to accept optional format parameter
- Check if value is boolean and format is specified
- Apply appropriate formatter or fall back to
ToString()
Formatter System:
public class BooleanFormatter
{
public string TrueValue { get; }
public string FalseValue { get; }
public BooleanFormatter(string trueValue, string falseValue)
{
TrueValue = trueValue;
FalseValue = falseValue;
}
public string Format(bool value) => value ? TrueValue : FalseValue;
}
Backward Compatibility
- ✅ No breaking changes - existing templates work as-is
- ✅ Format specifier is optional
- ✅ Plain
{{IsActive}} still outputs "True"/"False"
Future Extensions
This pattern can extend to other data types:
- Dates:
{{Date:yyyy-MM-dd}}
- Numbers:
{{Amount:N2}} or {{Amount:C}}
- Custom:
{{Status:uppercase}}
Testing Requirements
Documentation Updates
Community Feedback Requested
- Are the proposed format names intuitive? (checkbox, checkmark, yesno, etc.)
- Should we support culture-aware formatting by default?
- What other built-in formatters would be useful?
- Should format specifiers work for other types (dates, numbers)?
Use Case: This feature is particularly valuable for:
- Checklists and forms
- Status reports (active/inactive, enabled/disabled)
- Compliance documents (yes/no answers)
- Multi-language document generation
Problem
Currently, displaying boolean values in templates requires verbose conditional blocks:
For simple checkbox/boolean display, this is unnecessarily complex. Users want a simpler syntax for common boolean display patterns.
Proposed Solution
Add format specifier support to placeholders using the syntax:
{{VariableName:format}}Examples
Benefits
Implementation Considerations
1. Built-in Formatters (English)
Default formatters available out-of-the-box:
:checkbox→ ☑ / ☐:checkmark→ ✓ / ✗:yesno→ Yes / No:truefalse→ True / False:onoff→ On / Off:enabled→ Enabled / Disabled:active→ Active / Inactive2. Internationalization Support
Option A: Culture-Aware Formatting
Option B: Custom Formatter Registration
3. Technical Design
Syntax Parsing:
{{VariableName:format}}in placeholder detectionValue Conversion:
ValueConverter.ConvertToString()to accept optional format parameterToString()Formatter System:
Backward Compatibility
{{IsActive}}still outputs "True"/"False"Future Extensions
This pattern can extend to other data types:
{{Date:yyyy-MM-dd}}{{Amount:N2}}or{{Amount:C}}{{Status:uppercase}}Testing Requirements
Documentation Updates
BooleanFormatterCommunity Feedback Requested
Use Case: This feature is particularly valuable for: