docs.unity3d.com
    Show / Hide Table of Contents

    Template Formatter

    The Template Formatter lets you register reusable templates, and use them by name. Templates are useful when you want to format text in a particular way across multiple smart strings. When the string needs to be modified, you only need to do it in the template.

    Diagram showing the breakdown of the Smart String and how each part is evaluated.

    Example Smart String Template Arguments Result
    The initials are {0:template(initials)} initials = {name:substr(0,1)}} {surname:substr(0,1)}
    new { name = "Lara", surname = "Croft" }
    
    The initials are L C
    Hello {0.template(fullName)} fullName = {name} {surname}
    new { name = "Lara", surname = "Croft" }
    
    Hello Lara Croft
    The name is {name:t(highlight)}. highlight* = <color=red>{}</color>
    new { name = "Lara", surname = "Croft" }
    
    The name is <color=red>Lara</color>.
    The name is {surname:t(highlight)}. highlight* = <color=red>{}</color>
    new { name = "Lara", surname = "Croft" }
    
    The name is <color=red>Croft</color>.

    * To use the current value in scope, use an empty placeholder {}.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023