Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hugo template formatting in VS Code

The auto format in VS Code is making my code unreadable by removing indentations. I don't know how to turn this off for handlebars only.

Input:

{{ range ... }}
   {{ if .... }}
      {{if ... }}
          <tag></tag>
      {{end}}
   {{end}}
{{end}}

Output

{{ range ... }}
{{ if .... }}
{{if ... }}
<tag></tag>
{{end}}
{{end}}
{{end}}

Any way to prevent this?

like image 639
jemartin80 Avatar asked Sep 17 '19 19:09

jemartin80


People also ask

How do I fix the format in VS code?

VSCode – Code Formatting Shortcuts The code formatting is available in Visual Studio Code (VSCode) through the following shortcuts or key combinations: On Windows Shift + Alt + F. On macOS Shift + Option + F. On Linux Ctrl + Shift + I.

How do you add auto formatting in VS code?

VS Code Auto Format On SaveOpen Visual Studio Code editor. Click the “Settings” gear icon in the bottom-left corner. Search “Formatter” and click the “Editor: Default Formatter” option. From the drop-down menu, select whichever code formatter you want to use.


1 Answers

You can set the document type by using select Language Mode (change Language Mode ctrl + k + m), set the language to HTML template HTML Twig.

Then do formating, it will format perfect. It worked for me.

like image 180
Vishnu Prasad Avatar answered Nov 15 '22 10:11

Vishnu Prasad