vscode-twig-language
vscode-twig-language copied to clipboard
Twig Block Shorthand Synatx Indentation
The latest release 0.8.7
did not fix the indentation issue with using Twig block shorthand syntax issue #15. I still see unexpected block and HTML indentation. Also, closing HTML tags are often indented past the opening tag, and do not match in column.
For example, this HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>
{% if block('htmlTitle') is defined %}{{ block('htmlTitle') ~ ' - ' }}{% endif %}
Administration
</title>
<link rel="stylesheet" href="...link-to-file">
{% block head '' %}
</head>
<body>
{% include "@admin/includes/_alert.html" %}
{% block maintTitle 'CMS' %}
{% block leadText 'Lead text goes here...' %}
<section id="default" class="content-wrapper">
<div class="sidebar">
{% block sidebar '' %}
</div>
<main role="main" class="content">
{% block content '' %}
</main>
</section>
<script src="...link-to-file"></script>
{% block foot '' %}
</body>
</html>
Is formatted like this:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<title>
{% if block('htmlTitle') is defined %}
{{ block('htmlTitle') ~ ' - ' }}
{% endif %}
Administration
</title>
<link href="...link-to-file" rel="stylesheet">
{% block head '' %}
</head>
<body>
{% include "@admin/includes/_alert.html" %}
{% block maintTitle 'CMS' %}
{% block leadText 'Lead text goes here...' %}
<section class="content-wrapper" id="default">
<div class="sidebar">
{% block sidebar '' %}
</div>
<main class="content" role="main">
{% block content '' %}
</main>
</section>
<script src="...link-to-file"></script>
{% block foot '' %}
</body>
</html>
Note the extra indent on the {% block leadText %}
, and the closing tags on body
, section
, and div
.
Thank you for letting me know! There is an issue where block tags don't always need a closing "endblock" so I believe it is a problem/edge case for the formatter to parse. I raised it with the developer and he thought he fixed it but then reverted it when I realised twig has an "endblock" tag. I'll keep you updated and hopefully, we can find a solution soon!
I'm having a similar issue with the {{ head() }}
tag, used by CraftCMS
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
{% block head %}{% endblock %}
{{ head() }}
</head>
<body class="{{ bodyClasses is defined ? bodyClasses|join(" ") : "page" }}">
is adding an extra tag and going all funny
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
{% block head %}{% endblock %}
</head>
{{ head() }}</head><body
class="{{ bodyClasses is defined ? bodyClasses|join(" ") : "page" }}">
second save directly after first (no manual file changes) makes it even worse as it adds an extra
into the mix
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
{% block head %}{% endblock %}
</head>
{{ head() }}
</html></head><body
class="{{ bodyClasses is defined ? bodyClasses|join(" ") : "page" }}">
I just tested my example using version 0.9.0, and the formatting issue appears to be resolved. Thanks!