Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/_data/externalLinks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default {
"tsxNodeUse": "https://tsx.is/dev-api/entry-point"
"tsxNodeUse": "https://tsx.is/dev-api/entry-point",
"edgeJsDocs": "https://edgejs.dev",
"edgeJsPlugin": "https://github.com/reverentgeek/eleventy-plugin-edgejs"
}
4 changes: 4 additions & 0 deletions src/_data/templatetypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"name": "JSX",
"ext": "jsx",
"url": "/docs/languages/jsx/"
},{
"name": "Edge.js",
"ext": "edge",
"url": "/docs/languages/edgejs/"
},{
"name": "MDX",
"ext": "mdx",
Expand Down
1 change: 1 addition & 0 deletions src/docs/languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Not sure which one to choose? [Liquid](/docs/languages/liquid/) is a popular opt
.elv-page-toc-asterisk:before,
.elv-page-toc li:has(> a[href="/docs/languages/mdx/"]):after,
.elv-page-toc li:has(> a[href="/docs/languages/jsx/"]):after,
.elv-page-toc li:has(> a[href="/docs/languages/edgejs/"]):after,
.elv-page-toc li:has(> a[href="/docs/languages/handlebars/"]):after,
.elv-page-toc li:has(> a[href="/docs/languages/mustache/"]):after,
.elv-page-toc li:has(> a[href="/docs/languages/ejs/"]):after,
Expand Down
166 changes: 166 additions & 0 deletions src/docs/languages/edgejs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
eleventyNavigation:
parent: JavaScript
key: Edge.js
addedInVersion: 3.0.0
relatedTitle: Template Language—Edge.js
layout: layouts/langs.njk
---

<!-- {% tableofcontents "open" %} -->

| Eleventy Short Name | File Extension | npm Package |
| ------------------- | -------------- | ----------- |
| `edge` | `.edge` | [`eleventy-plugin-edgejs`]({{ externalLinks.edgeJsPlugin }}) |

- Related languages: [JavaScript](/docs/languages/javascript/), [JSX](/docs/languages/jsx/), [Custom](/docs/languages/custom/)

{% callout "info", "md" %}Edge.js requires Eleventy v3.0.0+, ESM (`"type": "module"` in your `package.json`), and Node.js >= 22.{% endcallout %}

## Installation

{%- set codeBlock %}
npm install eleventy-plugin-edgejs
{%- endset %}
{{ codeBlock | highlight("bash") | safe }}

## Configuration

{% addedin "3.0.0" %}Add the plugin to your Eleventy configuration file:

{% codetitle "eleventy.config.js" %}
{%- set codeBlock %}
import edgeJsPlugin from "eleventy-plugin-edgejs";

export default function (eleventyConfig) {
eleventyConfig.addPlugin(edgeJsPlugin);
}
{%- endset %}
{{ codeBlock | highlight("js") | safe }}

### Plugin Options

{% codetitle "eleventy.config.js" %}
{%- set codeBlock %}
import edgeJsPlugin from "eleventy-plugin-edgejs";

export default function (eleventyConfig) {
eleventyConfig.addPlugin(edgeJsPlugin, {
// Enable template caching (default: false)
cache: false,

// Add custom global variables/functions
globals: {},

// Provide your own Edge.js instance
eleventyLibraryOverride: undefined,
});
}
{%- endset %}
{{ codeBlock | highlight("js") | safe }}

## Usage

Edge.js templates use `{{ "{{" }} }}` for HTML-escaped output and `{{ "{{{" }} }}}` for raw (unescaped) output:

{%- set codeBlock %}
---
title: Hello World
---
<h1>{{ "{{" }} title }}</h1>
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

### Conditionals

{%- set codeBlock %}
@if(featured)
<span>Featured Post</span>
@elseif(pinned)
<span>Pinned</span>
@else
<span>Regular Post</span>
@end
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

### Loops

{%- set codeBlock %}
@each(post in collections.posts)
<li>{{ "{{" }} post.data.title }}</li>
@end
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

### Includes

Place partial templates in your `_includes` directory and reference them with `@include`:

{%- set codeBlock %}
@include("header")
<main>Page content</main>
@include("footer")
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

### Components and Slots

{%- set codeBlock %}
{{ "{{--" }} _includes/card.edge {{ "--" }}}}
<div class="card">
<h2>{{ "{{" }} title }}</h2>
{{ "{{{" }} $slots.main() }}}
</div>
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

{%- set codeBlock %}
@component("card", { title: "My Card" })
<p>Card content goes here.</p>
@end
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

### Comments

{%- set codeBlock %}
{{ "{{--" }} This is a comment and won't appear in the output {{ "--" }}}}
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

## Eleventy Integration

The plugin automatically bridges Eleventy filters, shortcodes, and paired shortcodes as Edge.js global functions.

### Filters

Eleventy filters are available as globals. Call them as functions in your templates:

{%- set codeBlock %}
{{ "{{" }} url("/my-page/") }}
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

### Shortcodes

Eleventy shortcodes are also available as globals:

{%- set codeBlock %}
{{ "{{" }} year() }}
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

### Paired Shortcodes

For paired shortcodes, the content is passed as the first argument:

{%- set codeBlock %}
{{ "{{" }} callout("This is the content", "warning") }}
{%- endset %}
{{ codeBlock | highlight("html") | safe }}

## Community Contributions

- {% indieweblink "eleventy-plugin-edgejs", externalLinks.edgeJsPlugin %}
- {% indieweblink "Edge.js documentation", externalLinks.edgeJsDocs %}