Highly possible that I have error logic but I'm just learning both JavaScript and Jekyll.
My goal is to manipulate an HTML element through JavaScript and place some Jekyll variable inside the inner HTML of that element. Everything is loading from a local development directory with jekyll serve
. I tried the following:
HTML:
<html>
<body>
<h2>Something</h2>
</body>
</html>
JavaScript:
document.addEventListener("DOMContentLoaded", function () {
manipulate = document.getElementsByTagName("h2");
manipulate[0].innerHTML = "{{ page.title }}";
});
Structure:
├── _config.yml
├── contact-us.md
├── css
│ └── main.scss
├── feed.xml
├── _includes
│ ├── footer.html
│ ├── header.html
│ ├── head.html
│ ├── readtime.html
│ └── sidebar.html
├── index.html
├── js
│ ├── anchor.js
│ └── tags.js
├── _layouts
│ ├── default.html
│ ├── page.html
│ ├── post.html
│ ├── single.html
│ └── tags.html
├── _posts
├── readme.md
├── _sass
│ ├── _base.scss
│ ├── _layout.scss
│ └── _syntax-highlighting.scss
├── _site
│ └── [...]
└── tags.md
I reached the tags.js from the tags.md
For example, if my page's title would be "foo", then I assumed the following HTML output in the <h2>
tag (this was my goal):
<h2>foo</h2>
But instead it gave me the following:
<h2>{{ page.title }}</h2>
I think it happened cause jekyll renders the values of the variables inside the jinja format and gives us the output, and after that I just placed the string "{{ page.title }}"
to the <h2>
tag.
I'm sure I'm missing something, but if you used something like that in one of your project, I'd appreciate any help.