Pretty Print Raw MiniJinja JSON Data On A Template
I use MiniJinja mj to create the templates for my site. The output data comes in from Serde se in a JSON like syntax. I use this snippet to pretty print it so it's easier to work with :
[] this is new code to look at :
rust
javascript
<input type="hidden" id="neo_string" value="{% autoescape true %}{{ page.all_sections() }}{% endautoescape %}" />
<pre id="neo_formatted"></pre>
<script>
const updateIt = => {
neo_formatted.innerText = JSON.stringify
}
document.addEventListener
</script>
- This goes in a template that receives data in a [TODO: Code shorthand span ] context variable
- The data is placed in a hidden input element to start with then scrubbed and output in the [TODO: Code shorthand span ] tag when the page is loaded
- I have optional values that come across in the origial data as [TODO: Code shorthand span ] without quotes. The script adds the qutoes to diminish parsing issues
Footnotes And References
- •
- •
- •
- •