Skip to content

Instantly share code, notes, and snippets.

@alexanderadam
Last active July 8, 2020 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderadam/00f40186d2797cfb9b1dffdc78dac445 to your computer and use it in GitHub Desktop.
Save alexanderadam/00f40186d2797cfb9b1dffdc78dac445 to your computer and use it in GitHub Desktop.
Properly debug Jekyll variables
---
layout: page
title: debug
permalink: /debug
---
<div id="jekyll-debug"></div>
<script>
var debugDiv = document.getElementById('jekyll-debug');
{% assign debug_variables = "site, page, layout, content, paginator" | split: ',' %}
var variables = {
{% for var in debug_variables %}
"{{ var }}": JSON.stringify(JSON.parse(decodeURIComponent("{{ [var] | jsonify | uri_escape }}")), null, 2),
{% endfor %}
};
for (var key in variables) {
var variableDiv = document.createElement('pre');
variableDiv.textContent = key + ":\n" + variables[key] + "\n";
document.body.appendChild(variableDiv);
}
</script>
@alexanderadam
Copy link
Author

I'm getting Liquid Warning: Liquid syntax error (line 8): [:open_square, "["] is not a valid expression in "{{ [var] | jsonify | uri_escape }}" but it seems to work anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment