Jinja2 templates in SQL/JSON injected into YAML
I have a bunch of YAML files that include both JSON and SQL as text string blocks in PyCharm 2023.1, for example:
# language=json
params: |
{# language=json #}
{
"end_date": {
"title": "End Date",
"default": "{{ now() }}"
}
}
# language=sql
query: |
{# language=sql #}
SELECT *
FROM my_table
WHERE created_at < {{ end_date }}
Is it possible for PyCharm to highlight both the JSON/SQL syntax as well as the Jinja2 templates?
These resolved issues seem to imply this should work:
- https://youtrack.jetbrains.com/issue/IDEA-106449
- https://youtrack.jetbrains.com/issue/PY-25277/Support-data-language-for-Jinja2-templates
However I can only get PyCharm to highlight either JSON/SQL OR Jinja2.
I have JSON, SQL, and YAML set as `Template File Types`, but once I added YAML to that list the JSON/SQL injection comment seems to just get ignored, and only the Jinja2 is highlighted.

Please sign in to leave a comment.
Unfortunately, that doesn't seem to be possible at the moment. Please follow the feature request I created https://youtrack.jetbrains.com/issue/IDEA-321651
Ahh too bad, thanks for making the ticket though Andrey Resler! Anything I can do to get this prioritized or speed along development? Would it be possible to write a plugin to accomplish this?
The issues are prioritized based on such factors as severity and number of affected users. You could ask your colleagues and friends to come vote for the issue as well.
A plugin should be possible. If you're interested, here are some resources:
- https://intellij-support.jetbrains.com/hc/en-us/community/topics/200366979-IntelliJ-IDEA-Open-API-and-Plugin-Development
- https://plugins.jetbrains.com/docs/intellij/welcome.html