I have an HTML file which is a Django template. For the most part, it's pretty boring, there's a bit of HTML and some Javascript code inside script tags.
The problem is that I've inserted a single line of Django template language (with the double curly braces), and it cascades into a thousand different errors on every line. How do I ignore this? All I can find is // @ts-ignore
on Google which doesn't seem to work with HTML files.
I don't even know where to begin. Is this a linting issue? What linter am I using, which documentation should I look at, etc. I assume I should be using the default tools for javascript. Please help!
The line in question is:
var achievementFlag = {{ achievement_flag|yesno:"true,false" }};
Naturally, the double curly braces is bad, as is the | and the :. And now the javascript just has squiggles all over it.
I have an HTML file which is a Django template. For the most part, it's pretty boring, there's a bit of HTML and some Javascript code inside script tags.
The problem is that I've inserted a single line of Django template language (with the double curly braces), and it cascades into a thousand different errors on every line. How do I ignore this? All I can find is // @ts-ignore
on Google which doesn't seem to work with HTML files.
I don't even know where to begin. Is this a linting issue? What linter am I using, which documentation should I look at, etc. I assume I should be using the default tools for javascript. Please help!
The line in question is:
var achievementFlag = {{ achievement_flag|yesno:"true,false" }};
Naturally, the double curly braces is bad, as is the | and the :. And now the javascript just has squiggles all over it.
Share Improve this question asked Dec 7, 2019 at 22:55 user3787031user3787031 1771 gold badge3 silver badges13 bronze badges 4- 1 Have you tried setting the language mode for the file in VS Code? Near the bottom right of the screen is the selected language. If you click on that, you can change the language. If Django template is not available, change the language to html (twig) - seems to be pretty close. code.visualstudio./docs/languages/… – NorthernDev Commented Dec 8, 2019 at 0:51
- The extensions for Django templates take away more features than they add in, so it hasn't been all that helpful. I was really hoping there'd be a simple way to ignore a line. Currently I'm just menting it out while I work on the rest of the code, but that's not a great way to tackle it in the long run. – user3787031 Commented Dec 8, 2019 at 7:32
- 1 Try the html(twig) extension. It doesn't take away much - it may not match Django 100%, but I believe you will be able to keep the js in the file – NorthernDev Commented Dec 9, 2019 at 0:35
- Sorry for the slow reply, but initially one of the Twig extensions was pretty horrible, but Twig Language 2 by mblode is fantastic and is now working as I'd like. Wasn't the solution I expected, but thanks a ton! – user3787031 Commented Dec 14, 2019 at 23:53
2 Answers
Reset to default 7Add this line to settings.json
"html.validate.scripts": false,
this line will make vscode ignores javascript validation in HTML files
credits: https://github./Microsoft/vscode/issues/17433#issuement-273870328
Another workaround I usually use is to use JSON.parse:
var achievementFlag = JSON.parse('{{ achievement_flag|yesno:"true,false" }}');