Home / Learn / Template Engines

Template Engines

Template engines take in tokenized strings and produce rendered strings with values in place of the tokens as output. Templates are typically used as an intermediate format written by developers to programmatically produce one or more desired output formats, commonly HTML, XML or PDF.

Why are template engines important?

Template engines allow developers to generate desired content types, such as HTML, while using some of the data and programming constructs such as conditionals and for loops to manipulate the output. Template files that are created by developers and then processed by the template engine consist of prewritten markup and template tag blocks where data is inserted.

For example, look at the first ten source lines of HTML of this webpage:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="author" content="Matt Makai">
  <meta name="description" content="Template engines provide programmatic output of formatted content such as HTML, XML or PDF.">
  <link rel="shortcut icon" href="//static.fullstackpython.com/fsp-fav.png">

Every one of the HTML lines above is standard for each page on Full Stack Python, with the exception of the `