Also, in with React.JS, complex expressions are usually rendered with helpers.
    
    
    import strformat, strutils, sugar, sequtils
    
    proc render_user*(user: tuple[name: string, is_human: bool, skills: 
seq[string]]): string =
      let human_partial  = if user.is_human: "<span>Human</span>" else: ""
      let skills_partial = user.skills.map((skill) => skill.to_upper)
      
      fmt"""
      <div id="user">
        <h1>{user.name}</h1>
        {human_partial}
        <span>{skills_partial}</span>
      </div>
      """
    
    echo render_user(("Jim Raynor", true, @["gun", "scout"]))
    
    
    Run

So, `fmt` looks like a reasonable solution for simple templates. If it could be 
improved to support arbitrary syntax would be even better.

Reply via email to