Skip to content

Changing Content Output

Posted on: Feb 15, 2021 by Stephanie Eckles
🍿 1 min. read

Learn how to change content output's file type and/or location within the filesystem.

The following techniques are applied via front matter.

The base file that you are using to create the altered content can use any of Eleventy's templating languages, and use all the features that language provides. For example, you could use Nunjucks or Liquid and loop through a collection to create JSON output.

Change Content's Output File Type

One of Eleventy's super powers that allows you to exceed the traditional limits of static is in using templating to create any file type output.

This is often used to create sitemaps and RSS feeds.

Changing the file type is done by simply appending the desired extension via the permalink:

permalink: "/{{ page.fileSlug }}.txt"

Learn more tips for constructing permalinks

Output Content Outside the Eleventy Filesystem

This is again done via permalink, and requires also setting permalinkBypassOutputDir: true which allows making our permalink relative to the project root using ./.

permalink: ./functions/{{ page.fileSlug }}.txt
permalinkBypassOutputDir: true
eleventyExcludeFromCollections: true

Notice we're also excluding it from all collections since we are intentionally creating it for purposes outside of our main site structure.

This technique is used to create page data for use by my social image plugin

View more quick tips