-
-
Notifications
You must be signed in to change notification settings - Fork 107
v2 TemplateFormatter
axunonb edited this page Feb 6, 2022
·
1 revision
Template Formatter allows you to register reusable templates, and use them by name.
var smart = Smart.CreateDefaultSmartFormat();
var templates = new TemplateFormatter(smart);
smart.AddExtensions(templates);
templates.Register("firstLast", "{First} {Last}");
templates.Register("lastFirst", "{Last}, {First}");
templates.Register("FIRST", "{First.ToUpper}");
templates.Register("last", "{Last.ToLower}");
templates.Register("NESTED", "{:template(FIRST)} {:template(last)}");
var user = new {First = "First", Last = "Last"};
smart.Format("{:template(firstLast)}", user);
// Uses the "{First} {Last}" template
smart.Format("{:template(NESTED)}", user);
// Uses the "{:template(FIRST)} {:template(last)}" template,
// which will then render "{First.ToUpper} {Last.ToLower}"
The following are equivalent:
{user:template:FIRST}
{user:template(FIRST)}
- Syntax, Terminology
- Placeholders and Nesting
- string.Format Compatibility
- Character Literals in Format Strings
- HTML With CSS or JavaScript
- Data Source Extensions
- Default _ DefaultFormatter
- Lists _ ListFormatter
- Choose _ ChooseFormatter
- Condition _ ConditionalFormatter
- Null _ NullFormatter
- SubString _ SubStringFormatter
- RegEx _ IsMatchFormatter
- Pluralization _ PluralLocalizationFormatter
- Localization _ LocalizationFormatter
- Templates _ TemplateFormatter
- TimeSpan _ TimeFormatter
- XML _ XElementFormatter
- Extension Methods
- Home
- Common Pitfalls
- HTML with CSS or JavaScript
- Overview
- Main Features
- Formatters
- Extra Features
- Console and StringBuilder
- TemplateFormatter
- SmartSettings to control Smart.Format behavior
- Additional Info
- License