Search code examples
haskellheist

Does heist support substituting (strings / JSON) into an arbitrary location within a template?


Regarding heist, I've got a template such as:

<script>
  var json = ???;
</script>
<h1>Example</h1>

Is there a way to substitute the ??? string with another string?

I think the following function might be the solution https://hackage.haskell.org/package/heist-1.0.1.0/docs/Heist-Splices-Json.html#v:bindJson but I have difficulty understanding that function and or what markup to use in the template.


Solution

  • No. You cannot substitute anything inside a <script> tag because the text inside a script tag is not treated as HTML. It's treated as plain text. If this was not done, you wouldn't be able to write JS code like if ( x < 42 ) because the less than would get treated as the beginning of a tag.