I’m writing html files that include several templates in twig template language. These are later used with twig-js document.getElementById('my-template').innerHTML
.
I want them to be highlighted as twig templates and my current solution is to inject the language using a comment:
<!-- language=twig -->
<script type="text/html" id="my-template">
<div>
{% if value %}
<b>{{value}}</b>
{% else %}
{{default}}
{% endif %}
</div>
</script>
I would rather just have <script type="text/x-twig" id="...">
and the IDE is doing the rest.
I don’t quite understand how the rules work.
- why is there no language twig although the twig plugin is enabled?
- I setup an xml tag injection for the tag script with XPath condition:
attribute::type="text/x-twig"
No matter what I try if the type is not text/html
it keeps showing javascript errors. Is there maybe a way to tell phpstorm that the mimetype text/x-twig
is a twig template?