🐕
Corgi
  • 🐕About Corgi
  • 🎓Learning Corgi
    • 📂File Structure
    • 🎉Getting Started
    • 🔟Code
    • 📄Arrow Blocks
    • 🪄If and Switch
    • ✏️Interpolation
    • 🔁For
    • 🤝Attributes
    • 🎭Expressions
    • 👮Security and Escaping
    • 💉Nonce Injection
    • ➡️Block Expansions
    • ➕Mixins
    • 📚Libraries
    • ✨The Standard Library
    • 💬Comments
    • ⛓️Filters
    • 🖨️Include
    • 👪Inheritance (Extending)
    • ⚡Breaking Changes
Powered by GitBook
On this page

Was this helpful?

  1. Learning Corgi

Getting Started

Corgi distinguishes between four file types: main files, library files, template files, and included files. While you'll learn about the last three later, let's talk about main files:

The main file is the file that gets compiled to a Go function. Therefore, unlike the other file types, it must define the name and parameters of it's output function. This is done by adding a Go function header without return value to your file:



func MyTemplateFunc(myArg string)

import __corgi_io "io"

func MyTemplateFunc(__corgi_w __corgi_io.Writer, myArg string) error {
    // ...
}

As you can see by the cryptic import alias and name for the io.Writer, corgi tries it best to avoid name collisions.

To do that, the corgi CLI prefixes all its identifiers with __corgi_. In turn, it reserves all identifiers starting with that name for current or future use.

You can also import other packages and use the types, functions, variables, and constants in it in your template.

import
  "time"
  // import aliases work too!
  linkedlist "container/list"


func F(t time.Time, l *linkedlist.List)

import (
    "time"
    __corgi_io "io"
    linkedlist "container/list"
)

func F(__corgi_w __corgi_io.Writer, t time.Time, l linkedlist.List) error {
    // ...
}

After you've written the function header, the content of generated document begins. Everything written there will be used to render the document.

Let's start with something very basic and create a p element:

func Engage()

doctype html
p Engage!


<!doctype html>
<p>Engage!</p>

From this point on, examples will only include a func directive, if its parameters are relevant for the example. When you also want to try the example, just give the function any name and no parameters!

PreviousFile StructureNextCode

Last updated 1 year ago

Was this helpful?

🎓
🎉