I am writing Django, Coding in template html using VS-Code IDE.
When Language Mode is set on Django HTML then VSCode not autocomplete HTML codes. (e.g. not auto-closing with </html> and so one)
Thus get autocomplete works on Django codes. (e.g. {% auto-closing %} and...)
And vice versa.
I need the VSCode Language Mode set on either Django HTML and HTML same, auto complete each one codes.
Related
I have been able to add syntax highlighting to my .liquid files by following the instructions here: Enabling Liquid templating syntax highlight in webStorm/phpStorm
It worked fine for my HTML and liquid syntax highlighting as it's so similar to Twig.
But my issue is I also have my schema included in each of my .liquid templates. The schema is JSON but there's not syntax highlighting on it at all.
Is there a way to add a custom syntax highlighting for a file type if it's wrapped in some sort of delimiter?
My schema is wrapped like so:
{% schema %}
JSON object with my settings/configuration
{% endschema %}
See image below:
As #yole have said: you cannot do that. Well... permanently.
You can always inject JSON there manually .. and it will last for a while (a session for sure).
Just place caret just after {% schema %} and hit Alt + Enter.
Choose Inject language or reference and locate JSON in the list (speed search works there as well, so just start typing).
Result is obvious:
You are using Twig plugin for .liquid files (native support for them (RUBY-7210) does not seem to be on JetBrains short list right now).
It's now possible to have permanent Language Injection in custom Twig tag (using Twig plugin). See the screenshot below for custom injection rule that you can create yourself:
You can inject JSON in your {% schema %} block manually via Alt+Enter, Inject language or reference > JSON:
See also https://blog.jetbrains.com/phpstorm/2017/12/twig-handling-improvements/
At my org we use a custom .amg filetype for an internal framework that is essentially just a JSON
I made IntelliJ treat those as JSONs by adding *.amg pattern under Recognized File Types > JSON
reference: JetBrains / File type associations
I have a newbie question. I've been recently trying out Django, and I notice that if I ever write a template tag of the sort:
{% if some_var < 10 %}
the < symbol is highlighted in sublime almost as if it's a syntax error (or warning). Now of course it works correctly, but I'm wondering why this highlighting occurs in the first place. Do some browsers have difficulty parsing < when reading HTML code or something? Please enlighten me (and > doesn't get highlighted to make matters worse!).
I'm actually considering writing a custom template tag that performs the "is less than" comparison.
Sublime probably thinks your template is a plain HTML file, in which case < and > are elements of HTML tags and don't make sense anywhere else.
You might be able to manually set the filetype to be a Django template which should fix the highlighting.
Check out the Djaneiro package. It contains an HTML (Django) syntax definition that contains scopes for template tags:
(The color scheme is my Neon Color Scheme, which contains colors specifically for Djaneiro)
Another option is to upgrade to Sublime Text 3, which is highly recommended anyway. The default HTML syntax definition (along with many other languages, including JavaScript, PHP, and Python) has been completely rewritten, and template tags are now ignored:
I have a django project.
index.html page of it contains a form with submit button. I want to include django-template in this index.html page to send email with data from this form. Is it possible to do without any python-code? Just like:
{% send_mail( {{ request.GET.to }}, {{ request.GET.subject }}, {{ request.GET.message }} %}
P.S. I am new to django.
This wont work. Django template is not designed to call python modules/methods directly.
You can either create a template tag, or on click, trigger a url/view that would send the email.
From the philosophy of django template language
If you have a background in programming, or if you’re used to languages which mix programming code directly into HTML, you’ll want to bear in mind that the Django template system is not simply Python embedded into HTML. This is by design: the template system is meant to express presentation, not program logic.
Documentation on how to create template tags
And here is a nice tutorial talking about the email sending functionality through views.py
No, that's not possible. In order for those values request.GET.to to be populated, you have to click the submit button - which has to go somewhere.
Now, if you really must - you can do this strictly from the browser using javascript and a library like mailgun which works over HTTP.
Simply create a request just like you would any AJAX request, read the contents of the form fields and your email message will be sent - without ever touching your server-side code.
PhpStorm can apply code style rules for specific languages with the Reformat Code command. PhpStorm can also recognize a language embedded within a file of another language (known in PhpStorm as 'Language Injection'). So, I expect that a language would be subject to its code style rules wherever the language is used -- whether embedded or in its own file.
I've found that this works as expected for css/js within an html file, but not for language injections within PHP files. PhpStorm will recognize css within a heredoc, and html as a heredoc and in single- and double- quoted strings -- yet reformatting does not work in any of these cases.
Short of using an intermediary file to reformat the code, how can I get PhpStorm to reformat these sections of code? I am using PhpStorm 6.0.3 for Mac.
Their documentation states:
PhpStorm supports full coding assistance for:
CSS and JavaScript in an HTML or XML file.
CSS, JavaScript, and SQL outside PHP code blocks and inside PHP string literals.
The second bullet seems only half true, as css/js/sql are recognized but not subjected to code styles inside PHP string literals. And injected html is not specified; but between PhpStorm recognizing the language injections and its capability to apply code styles to an arbitrary selection, all the pieces for formatting embedded languages seem to be there. What am I missing?
To reformat injected code according to PhpStorm code styles Preferences, select the injected code and open the Intention Actions list (Alt+Enter), and select "Edit __ Fragment" to edit it in it's own dedicated window (documentation). In this window, code formatting will work as expected.
I'm trying to edit phpbb HTML template file with Eclipse Ganymedes version 3.4.1 containing Web Developer Tools.
These template files contain HTML markup with template variable marks in form {variable_name}. Now, when trying to open such file, Eclipse trys to validate also these template variable marks.
For example template contains
<meta http-equiv="content-type" content="text/html; charset={S_CONTENT_ENCODING}" />
After opening Eclipse shows on editor body:
Unsupported Character Body
Character encoding "{S_CONTENT_ENCODING}" is not supported by this platform.
<button>Set encoding...</button>
How to solve this using WTP or is there any better editor for template editing purpose ?
Eclipse is trying to determine the text encoding from your meta tags and fails.
To override this behavior open the file in eclipse so you can see the error. Open the File menu and choose Properties (Alt-Enter) and eclipse will show you the properties dialog for the file where you can change the text file encoding.
I don't know if this can be disabled for all the files.
I've never used Eclipse on Linux, but it looks like the problem isn't really about Eclipse supporting variables -- it's about it trying to render what a character set that it thinks is called "{S_CONTENT_ENCODING}"
You can probably get around the problem by changing {S_CONTENT_ENCODING} to utf-8 (or latin-1 or whatever) in all of your templates. (This assumes that you aren't changing encoding from one template to the next, but I really doubt you are.)
Copy-paste utf-8 where you see {S_CONTENT_ENCODING} in one of the templates, and Eclipse should handle it the other {foo} instances from there.