\documentclass[
  paper=a4,
  parskip=half,
  firstfoot=false,
  enlargefirstpage=true,
]{scrlttr2}
\usepackage{xcolor}
\definecolor{texsmithLinkColor}{HTML}{0B3D91}
\VAR{extra_packages}
\usepackage{graphicx}
\usepackage[\VAR{babel_language|default('english')}]{babel}
\usepackage[
    colorlinks=true,
    linkcolor=texsmithLinkColor,
    urlcolor=texsmithLinkColor,
    citecolor=texsmithLinkColor]{hyperref}
\LoadLetterOption{\VAR{letter_standard_option}}
\KOMAoptions{foldmarks=\VAR{foldmarks_option}}
\BLOCK{ set margin_style = margin|default('default')|lower }
\BLOCK{ set margin_literal = margin_style not in ["narrow", "default", "wide"] }
\BLOCK{ if margin_style == "narrow" }
\KOMAoptions{fromalign=left, backaddress=false}
\setlength{\oddsidemargin}{1cm}
\BLOCK{ elif margin_style == "wide" }
\KOMAoptions{fromalign=left, backaddress=false}
\setlength{\oddsidemargin}{2cm}
\BLOCK{ elif margin_literal }
\KOMAoptions{fromalign=left, backaddress=false}
\setlength{\oddsidemargin}{0cm}
\addtolength{\textwidth}{-\VAR{margin}}
\BLOCK{ endif }
\BLOCK{ if use_cursive_signature }
\setmainfont[Path=fonts/,Extension=.otf,Ligatures=Common,Mapping=]{modernline}
\newcommand{\TexsmithLetterEndash}{\kern0.05em-\kern0.05em}
\newcommand{\TexsmithLetterEmdash}{\kern0.05em-\kern0.05em-\kern0.05em}
\catcode"2013=\active
\catcode"2014=\active
\begingroup\lccode`~="2013\lowercase{\endgroup\protected\def~}{\TexsmithLetterEndash}
\begingroup\lccode`~="2014\lowercase{\endgroup\protected\def~}{\TexsmithLetterEmdash}
\BLOCK{ endif }

\BLOCK{ if preamble }
% Custom document preamble injected from overrides.
\VAR{preamble}

\BLOCK{ endif }

\BLOCK{ if use_cursive_signature }
\newfontfamily\SignatureFont[Path=fonts/,Extension=.otf]{modernline}
\newcommand{\SignatureText}[1]{{\SignatureFont #1}}
\BLOCK{ else }
\newcommand{\SignatureText}[1]{#1}
\BLOCK{ endif }

\newcommand{\SignatureBlock}{%
\BLOCK{ if has_signature_image }
  \includegraphics[height=1.6cm]{\VAR{signature_image_path}}
  \\[-0.25\baselineskip]%
\BLOCK{ endif }
  \SignatureText{\VAR{signature_text}}%
}

\setkomavar{fromname}{\VAR{from_name}}
\setkomavar{fromaddress}{%
\BLOCK{ if has_sender_address }
  \VAR{from_address_lines|join('\\\\\n')}
\BLOCK{ endif }
}
\BLOCK{ if from_location_value -}
\setkomavar{location}{\VAR{from_location_value}}\BLOCK{ endif }
\BLOCK{ set effective_date = date_value|default('')|trim }
\setkomavar{date}{\BLOCK{ if effective_date -}
\VAR{date_value}\BLOCK{ else }\today\BLOCK{ endif }}
\BLOCK{ if has_subject }
\setkomavar{subject}{\VAR{object_value}}
\setkomavar*{subject}{\VAR{subject_prefix}}
\BLOCK{ endif }
\setkomavar{signature}{\SignatureBlock}
\BLOCK{ if has_back_address }
\setkomavar{backaddress}{%
  \VAR{back_address_lines|join('\\\\\n')}
}
\BLOCK{ endif }
\BLOCK{ if reference_value }
\setkomavar{myref}{\VAR{reference_value}}
\BLOCK{ endif }
\BLOCK{ if not reference_fields_enabled }
\removereffields
\BLOCK{ endif }
\renewcommand*{\raggedsignature}{\VAR{signature_alignment_command}}

\begin{document}

\begin{letter}{%
\BLOCK{ if has_recipient_address }
  \VAR{to_address_lines|join('\\\\\n  ')}
\BLOCK{ else }
  \VAR{to_name}
\BLOCK{ endif }
}

\opening{\VAR{opening_text}}

\VAR{mainmatter}

\VAR{backmatter}
\VAR{fragment_backmatter}

\BLOCK{ if has_closing }
\closing{\VAR{closing_text}}
\BLOCK{ endif }
\BLOCK{ if has_postscript }
\ps{PS: \VAR{postscript_text}}
\BLOCK{ endif }

\end{letter}
\BLOCK{ if not page_numbers }
\pagenumbering{gobble}
\thispagestyle{empty}
\pagestyle{empty}
\BLOCK{ endif }

\end{document}
