Skip to content

A way to load a script for single page? #2506

Answered by cfjedimaster
gasatrya asked this question in Q&A
Discussion options

You must be logged in to vote

The simplest solution is to just add the script tag. If you are using Markdown templates, nothing stops you from using HTML, nor any of the other ones. Eleventy lets you output any HTML you want.

Now if you want to get fancier and ensure it gets loaded in the HEAD part of your doc and you are using an Eleventy layout template, use front matter to specify something, have the layout template look for it and optionally load it. For example:

---
title: Generator page
script: generator.js
---

And in your layout, if script is defined, you can output <script src="{{ script }}"></script>.

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@pdehaan
Comment options

@gasatrya
Comment options

Answer selected by gasatrya
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants