Squirrelly
Get StartedTemplate SyntaxAPICommunity
7.x.x
7.x.x
  • Overview
  • FAQ
  • Demo
  • Performance
  • Changelog
  • Getting Started
    • Installation
    • Your First Template
    • Why Squirrelly?
    • What's a template engine?
  • Template Syntax
    • The Basics
    • Global References
    • Helper References
    • Filters
    • Helpers
    • Self-Closing Helpers
    • Native Helpers
    • Setting custom tags
    • Partials
    • Built-in Helpers
  • API
    • API Overview
    • Compile
    • Render
    • renderFile
    • load
    • defineFilter
    • setDefaultFilters
    • autoEscaping
    • defineHelper
    • defineNativeHelper
    • definePartial
    • defaultTags
  • Recipes
    • Squirrelly with ExpressJS
  • Guides
    • Generating Badges with Squirrelly
Powered by GitBook
On this page
  • Browser Demo
  • 1. Install Squirrelly
  • 2. Create a Template
  • 3. Render your Template!
  1. Getting Started

Your First Template

PreviousInstallationNextWhy Squirrelly?

Last updated 5 years ago

Browser Demo

1. Install Squirrelly

Follow the installation instructions, then require or import Squirrelly. In this example, we'll require Squirrelly as the variable Sqrl.

var Sqrl = require("squirrelly")
//Or you could: import * as Sqrl from "squirrelly"
//Or, if you're in the browser, Sqrl is already global

2. Create a Template

var myTemplate = `
This is a template
My favorite template engine is: {{fav}}
My favorite kind of cake is: {{cake}}
`

In this example, we're using JavaScript template literals. You don't have to use template literals with Squirrelly. It just makes it easier to write templates, since you don't have to escape newlines. In real life, most templates are their own files.

3. Render your Template!

var templateResult = Sqrl.Render(myTemplate, {
    fav: "Squirrelly", cake: "Chocolate"
})
console.log(templateResult)
//This is a template
//My favorite template engine is: Squirrelly
//My favorite kind of cake is: Chocolate

Try rendering it with other data: it still works!