HAML | JSON: Add a Script Tag of Type Application/

2019-08-08 17:50发布

问题:

Write a Script Tag With the Type Application/JSON

This is about as straight-forward as it sounds. I'd like the HAML equivalent of:

<script class="_config" type="application/json">
    {
        "template": "#myId",
        "css": {
            "background": "#fff",
            "opacity": "0.8"
        }
    }
</script>

As of now, the only solution is...

%script._config{ type: 'application/json' }
  { |
    "template": "#id", |
    "css": { "background": "#fff" } |
  }

... Which sucks -- it renders the JSON in the page. Also, there should be no need to write the 'multiline' pipes. If its application/json, why wouldn't HAML know to parse it without normal indentation rules?

Any way to write this without the need of pipe characters?

Thanks!