Skip to content

Latest commit

 

History

History
90 lines (63 loc) · 3.17 KB

data-eleventy-supplied.md

File metadata and controls

90 lines (63 loc) · 3.17 KB
eleventyNavigation
parent key order
Using Data
Eleventy Supplied Data
0.5

Eleventy Supplied Data

Here are a few data values we supply to your page that you can use in your templates:

  • pkg: The local project’s package.json values.
  • pagination, when enabled using pagination in front matter. Read more about Pagination.
  • collections: Lists of all of your content, grouped by tags. Read more about Collections
  • page: Has information about the current page. See code block below for page contents. For example, page.url is useful for finding the current page in a collection. Read more about Collections (look at Example: Navigation Links with an active class added for on the current page).

page Variable Contents:

let page = {
  
  // URL can be used in <a href> to link to other templates
  url: "/current/page/myFile/",
  
  // For permalinks: inputPath filename minus template file extension (New in v0.3.4)
  fileSlug: "myFile",

  // For permalinks: inputPath minus template file extension (New in v0.9.0)
  filePathStem: "/current/page/myFile",
  
  // JS Date Object for current page (used to sort collections)
  date: new Date(),
  
  // The path to the original source file for the template
  // Note: this will include your input directory path!
  inputPath: "./current/page/myFile.md",
  
  // Depends on your output directory (the default is _site)
  // You probably won’t use this: `url` is better.
  outputPath: "./_site/current/page/myFile/index.html"
};

date

The date associated with the page. Defaults to the content’s file created date but can be overridden. Read more at Content Dates.

fileSlug {% addedin "0.3.4" %}

The fileSlug variable is mapped from inputPath and is useful for creating your own clean permalinks.

inputPath page.fileSlug Result
"2018-01-01-myFile.md" "myFile"
"myDir/myFile.md" "myFile"

fileSlug returns information on the parent directory if the file is an index template:

inputPath page.fileSlug Result
"index.md" "" (empty)
"myDir/index.md" "myDir"
"myDir/2018-01-01-index.md" "myDir"

filePathStem {% addedin "0.9.0" %}

The filePathStem variable is mapped from inputPath and is useful if you’ve inherited a project that doesn’t use clean permalinks.

{% callout "info" %}Careful with this one and remember that Cool URI’s don’t change.{% endcallout %}

If you absolutely need a file extension on your output, you might use it like this:

{% codetitle "YAML Front Matter", "Syntax" %}

{% raw %}

---
permalink: "{{ page.filePathStem }}.html"
---

{% endraw %}

Example Output below is using the above permalink value.

inputPath page.filePathStem Result Example Output
"2018-01-01-myFile.md" "myFile" myFile.html
"myDir/myFile.md" "myDir/myFile" myDir/myFile.html