Upgrade to PRO for Only $50/Yearโ€”Limited-Time Offer! ๐Ÿ”ฅ

Templating: Eleventy's Superpower

Templating: Eleventy'sย Superpower

Presented at the first Eleventy Meetup, July 15, 2021.

One of the many cool features of Eleventy is its support of multiple template languages. But what the heck are template languages and how can you use them to make your static Eleventy sites feel like the dynamic, server-rendered sites of yore?

Video: https://www.youtube.com/watch?v=rZyNBd1WgVM

Avatar for Mike Aparicio

Mike Aparicio

July 15, 2021
Tweet

More Decks by Mike Aparicio

Other Decks in Programming

Transcript

  1. <html> <head> <title>Mike Aparicio < / title> < / head>

    <body> <div class="header"> <h1><a href="/">Mike Aparicio < / a> < / h1> <ul> <li><b><a href="/">Home < / a> < / b> < / li> <li><a href="/about.html">About < / a> < / li> <li><a href="/blog.html">Blog < / a> < / li> < / ul> < / div> <div class="main"> . . . < / div> <div class="footer"> <p>&copy; 1999 All your rights are belong to us < / p> < / div> < / body> < / html>
  2. <?php include("externals/header.php"); ?> <div class="main"> . . . < /

    div> <?php include("externals/footer.php"); ?>
  3. Markdown (2004) Liquid (2006) HAML (2006) Mustache (2009) EJS (2010)

    Handlebars (2011) Pug (2010) Nunjucks (2012)
  4. Objects/Variables Data storage {{ page.title }} Filters Apply functions to/manipulate

    data {{ page.title | capitalize }} Tags Iterate over/conditionally display data {% if page.title %} โ€จ ... {% endif %} {% for pages as page %} โ€จ ... {% endfor %}
  5. Markdown Liquid HAML Mustache EJS Handlebars Pug Nunjucks JavaScript (as

    11ty.js) HTML (as anything!) Eleventy Template Languages
  6. <html> <head> <title>Mike Aparicio < / title> <meta name="description" content="An

    Eleventy demo site."> < / head> <body> <header> <h1><a href="/">Mike Aparicio < / a> < / h1> < / header> <nav> <ul> <li><a href="/">Home < / a> < / li> <li><a href="/about.html">About < / a> < / li> <li><a href="/blog.html">Blog < / a> < / li> < / ul> < / nav> <main> . . . < / main> <footer> <p>&copy; 2021 All your rights are belong to us < / p> < / footer> < / body> < / html>
  7. <html> <head> <title>Mike Aparicio < / title> <meta name="description" content="An

    Eleventy demo site."> < / head> <body> <header> <h1><a href="/">Mike Aparicio < / a> < / h1> < / header> <nav> <ul> <li><a href="/">Home < / a> < / li> <li><a href="/about.html">About < / a> < / li> <li><a href="/blog.html">Blog < / a> < / li> < / ul> < / nav> <main> {{ content | safe }} < / main> <footer> <p>&copy; 2021 All your rights are belong to us < / p> < / footer> < / body> < / html> ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk ๐Ÿ“ assets ๐Ÿ“ pages .eleventy.js .gitignore package.json README.md Layouts
  8. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk ๐Ÿ“

    assets ๐Ÿ“ pages home.html .eleventy.js .gitignore package.json README.md Front Matter - - - layout: base - - - <p>Here's the content of our homepage. < / p>
  9. ๐Ÿ“ _site ๐Ÿ“ pages ๐Ÿ“ home index.html ๐Ÿ“ _src ๐Ÿ“

    _data ๐Ÿ“ _includes base.njk ๐Ÿ“ assets ๐Ÿ“ pages home.html .eleventy.js .gitignore package.json README.md <html> <head> <title>Mike Aparicio < / title> <meta name="description" content="An Eleventy demo site."> < / head> <body> <header> <h1><a href="/">Mike Aparicio < / a> < / h1> < / header> <nav> <ul> <li><a href="/">Home < / a> < / li> <li><a href="/about.html">About < / a> < / li> <li><a href="/blog.html">Blog < / a> < / li> < / ul> < / nav> <main> <p>Here's the content of our homepage. < / p> < / main> <footer> <p>&copy; 2021 All your rights are belong to us < / p> < / footer> < / body> < / html>
  10. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk ๐Ÿ“

    assets ๐Ÿ“ pages home.html .eleventy.js .gitignore package.json README.md Permalink - - - layout: base permalink: / - - - <p>Here's the content of our homepage. < / p>
  11. ๐Ÿ“ _site index.html ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk

    ๐Ÿ“ assets ๐Ÿ“ pages home.html .eleventy.js .gitignore package.json README.md <html> <head> <title>Mike Aparicio < / title> <meta name="description" content="An Eleventy demo site."> < / head> <body> <header> <h1><a href="/">Mike Aparicio < / a> < / h1> < / header> <nav> <ul> <li><a href="/">Home < / a> < / li> <li><a href="/about.html">About < / a> < / li> <li><a href="/blog.html">Blog < / a> < / li> < / ul> < / nav> <main> <p>Here's the content of our homepage. < / p> < / main> <footer> <p>&copy; 2021 All your rights are belong to us < / p> < / footer> < / body> < / html>
  12. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk ๐Ÿ“

    assets ๐Ÿ“ pages about.html home.html .eleventy.js .gitignore package.json README.md - - - layout: base permalink: /about/ title: "About" - - - <p>Here's the content of our About page. < / p>
  13. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk ๐Ÿ“

    assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md Directory Data { "layout": "base", "permalink": "/{{ title | slug }}/" }
  14. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk ๐Ÿ“

    assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md - - - title: "About" - - - <p>Here's the content of our About page. < / p>
  15. <html> <head> <title>Mike Aparicio < / title> <meta name="description" content="An

    Eleventy demo site."> < / head> <body> <header> <h1><a href="/">Mike Aparicio < / a> < / h1> < / header> <nav> <ul> <li><a href="/">Home < / a> < / li> <li><a href="/about.html">About < / a> < / li> <li><a href="/blog.html">Blog < / a> < / li> < / ul> < / nav> <main> <p>Here's the content of our About page. < / p> < / main> <footer> <p>&copy; 2021 All your rights are belong to us < / p> < / footer> < / body> < / html> ๐Ÿ“ _site ๐Ÿ“ about index.html ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md
  16. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data site.json ๐Ÿ“ _includes base.njk

    ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md Global Data { "name": "Mike Aparicio", "description": "An Eleventy demo site." }
  17. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data site.json ๐Ÿ“ _includes base.njk

    ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md Tags <html> <head> <title> {{ site.name }}{% if title %} - {{ title }}{% endif %} < / title> <meta name="description" content=" {% if description %} {{ description }} {% else %} {{ site.description }} {% endif %}"> < / head> <body> . . . < / body> < / html>
  18. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data site.json ๐Ÿ“ _includes base.njk

    ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md - - - title: "About" description: "The About page." - - - <p>Here's the content of our About page. < / p>
  19. ๐Ÿ“ _site ๐Ÿ“ about index.html ๐Ÿ“ _src ๐Ÿ“ _data site.json

    ๐Ÿ“ _includes base.njk ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md <html> <head> <title>Mike Aparicio - About < / title> <meta name="description" content="The About page."> < / head> <body> <header> <h1><a href="/">Mike Aparicio < / a> < / h1> < / header> <nav> <ul> <li><a href="/">Home < / a> < / li> <li><a href="/about.html">About < / a> < / li> <li><a href="/blog.html">Blog < / a> < / li> < / ul> < / nav> <main> <p>Here's the content of our About page. < / p> < / main> <footer> <p>&copy; 2021 All your rights are belong to us < / p> < / footer> < / body> < / html>
  20. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data nav.json site.json ๐Ÿ“ _includes

    base.njk ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md Navigation { "items": [ { "url": "/", "name": "Home" }, "url": "/about/", "name": "About" }, "url": "/blog/", "name": "Blog" } ] }
  21. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data nav.json site.json ๐Ÿ“ _includes

    base.njk ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md Iteration <html> <head> . . . < / head> <body> <header> <h1>{{ site.name }} < / h1> < / header> <nav> <ul> {% for item in nav.items %} <li><a href="{{ item.url }}" {% if item.url = = = page.url %} aria - current="page" data - state="active" {% endif %} >{{ item.name }} < / a> < / li> {% endfor %} < / ul> < / nav> . . . < / body> < / html>
  22. ๐Ÿ“ _site ๐Ÿ“ about index.html ๐Ÿ“ _src ๐Ÿ“ _data nav.json

    site.json ๐Ÿ“ _includes base.njk ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md <html> <head> <title>Mike Aparicio - About < / title> <meta name="description" content="The About page."> < / head> <body> <header> <h1><a href="/">Mike Aparicio < / a> < / h1> < / header> <nav> <ul> <li><a href="/">Home < / a> < / li> <li><a href="/about.html" aria - current="page" data - state="active">About < / a> < / li> <li><a href="/blog.html">Blog < / a> < / li> < / ul> < / nav> <main> <p>Here's the content of our About page. < / p> < / main> <footer> <p>&copy; 2021 All your rights are belong to us < / p> < / footer> < / body> < / html>
  23. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data nav.json site.json ๐Ÿ“ _includes

    base.njk ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md https://11ty.rocks/eleventyjs/dates/#year-shortcode Shortcodes module.exports = function(eleventyConf i g) { โ€จ eleventyConf i g.addShortcode("year", () = > `${new Date().getFullYear()}` ); };
  24. <html> <head> . . . < / head> <body> <header>

    <h1><a href="/">{{ site.name }} < / a> < / h1> < / header> <nav> <ul> {% for item in nav.items %} . . . {% endfor %} < / ul> < / nav> <main> {{ content | safe }} < / main> <footer> <p>&copy; {{ year }} All your rights are belong to us < / p> < / footer> < / body> < / html> ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data nav.json site.json ๐Ÿ“ _includes base.njk ๐Ÿ“ assets ๐Ÿ“ pages about.html home.html pages.json .eleventy.js .gitignore package.json README.md
  25. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes ๐Ÿ“ assets

    ๐Ÿ“ blog f i rst - entry.md ๐Ÿ“ pages .eleventy.js .gitignore package.json README.md Markdown - - - title: "Blog Entry #1" layout: base permalink: /blog/{{ title | slug }}/ description: "This is my f i rst blog post." - - - # # {{ title }} Lorem ipsum dolor sit * * amet consectetur * * adipisicing elit. Voluptatibus facilis reiciendis dolores molestias, perferendis dolore odio, quia ratione aliquam vero quo praesentium! Ut quo, [fugiat maiores](https: / / 11ty.dev) ipsum voluptate commodi neque! - Markdown - Liquid - HAML - Mustache - Pug - EJS - Handlebars - Nunjucks Lorem ipsum dolor sit amet consectetur adipisicing elit. Architecto ullam off i ciis sit quo reprehenderit expedita, inventore enim cum consectetur?
  26. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes ๐Ÿ“ assets

    ๐Ÿ“ blog blog.json f i rst - entry.md ๐Ÿ“ pages .eleventy.js .gitignore package.json README.md Collections { "layout": "blog", "permalink": "/blog/{{ title | slug }}/", "tags": "posts" }
  27. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk blog.njk

    ๐Ÿ“ assets ๐Ÿ“ blog blog.json f i rst - entry.md ๐Ÿ“ pages .eleventy.js .gitignore package.json README.md Layout Chaining - - - layout: base - - - <article> {{ content | safe }} < / article>
  28. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes base.njk blog.njk

    ๐Ÿ“ assets ๐Ÿ“ blog blog.json f i rst - entry.md second - entry.md third - entry.md ๐Ÿ“ pages .eleventy.js .gitignore package.json README.md - - - title: "Blog Entry #3" description: "This is my third blog post." - - - Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque animi delectus laboriosam, dicta exercitationem magni vel hic perferendis consequuntur nisi, quasi ut commodi corrupti praesentium ad consequatur at! Dignissimos, nam?
  29. ๐Ÿ“ _site ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“ _includes ๐Ÿ“ assets

    ๐Ÿ“ blog ๐Ÿ“ pages about.html blog.html home.html pages.json .eleventy.js .gitignore package.json README.md - - - title: "Blog" description: "The Blog page." - - - <ul> {% for post in collections.posts %} <li><a href="{{ post.url }}">{{ post.data.title }} < / a> < / li> {% endfor %} < / ul>
  30. ๐Ÿ“ _site ๐Ÿ“ blog index.html ๐Ÿ“ _src ๐Ÿ“ _data ๐Ÿ“

    _includes ๐Ÿ“ assets ๐Ÿ“ blog ๐Ÿ“ pages about.html blog.html home.html pages.json .eleventy.js .gitignore package.json README.md <html> <head> <title>Mike Aparicio - Blog < / title> <meta name="description" content="The Blog page."> < / head> <body> . . . <nav> <ul> <li><a href="/">Home < / a> < / li> <li><a href="/about.html">About < / a> < / li> <li><a href="/blog.html" aria - current="page" data - state="active">Blog < / a> < / li> < / ul> < / nav> <main> <h2>Blog < / h2> <ul> <li><a href="/blog/blog - entry-1">Blog Entry #1 < / a> < / li> <li><a href="/blog/blog - entry-2">Blog Entry #2 < / a> < / li> <li><a href="/blog/blog - entry-3">Blog Entry #3 < / a> < / li> < / ul> < / main> . . . < / body> < / html>
  31. Agility CMS Bloomreach Bold (Quintype) Butter CMS Cockpit CMS Contentful*

    Contentstack Core dna CoreMedia Content Cloud Cosmic JS Craft CMS* Crownpeak Dato CMS Directus DNN Evoq Content dotCMS Episerver eZ Platform FirstSpirit (e-Spirit) GraphCMS Ingeniux CMS Kontent.ai (Kentico) Liferay Magnolia CMS Mura Netlify CMS* Prismic.io* Sanity* Scrivito Sitecore Sitefinity Solodev Strapi* Zesty.io An Incomplete List of Headless CMSs https://www.cmswire.com/web-cms/13-headless-cmss-to-put-on-your-radar/ * services Mike actually heard of before preparing this talk, fwiw