You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This Plugin enables Prettier to format `.twig` files, as well as `.html.twig`.
16
15
17
-
## Install
16
+
## Installation
18
17
19
18
```bash
20
19
yarn add --dev @zackad/prettier-plugin-twig
21
20
```
22
21
23
-
## Use
22
+
## Configuration
24
23
25
-
```bash
26
-
prettier --write "**/*.twig"
27
-
```
28
-
29
-
In your editor, if the plugin is not automatically picked up and invoked (e.g., if you are using format on save, but no formatting is happening when you save), try adding the plugin explicitly in your Prettier configuration (e.g., `.prettierrc.json`) using the `plugins` key:
24
+
Add the plugin explicitly into your Prettier configuration (e.g., `.prettierrc.json`) using the `plugins` key:
30
25
31
26
```json
32
27
{
33
-
"printWidth": 80,
34
-
"tabWidth": 4,
35
28
"plugins": ["@zackad/prettier-plugin-twig"]
36
29
}
37
30
```
38
31
32
+
## Usage
33
+
34
+
```bash
35
+
./node_modules/.bin/prettier --write "**/*.twig"
36
+
```
37
+
39
38
## Options
40
39
41
40
This Prettier plugin comes with some options that you can add to your Prettier configuration (e.g., `prettierrc.json`).
@@ -75,12 +74,14 @@ Choose whether to output the block name in `{% endblock %}` tags (e.g., `{% endb
75
74
An array of coherent sequences of non-standard Twig tags that should be treated as belonging together. Example (inspired by [Craft CMS](https://docs.craftcms.com/v2/templating/nav.html)):
76
75
77
76
```json
78
-
twigMultiTags: [
79
-
"nav,endnav",
80
-
"switch,case,default,endswitch",
81
-
"ifchildren,endifchildren",
82
-
"cache,endcache"
83
-
]
77
+
{
78
+
"twigMultiTags": [
79
+
"nav,endnav",
80
+
"switch,case,default,endswitch",
81
+
"ifchildren,endifchildren",
82
+
"cache,endcache"
83
+
]
84
+
}
84
85
```
85
86
86
87
Looking at the case of `nav,endnav`, this means that the Twig tags `{% nav %}` and `{% endnav %}` will be treated as a pair, and everything in between will be indented:
@@ -110,10 +111,12 @@ Note that the order matters: It has to be `"nav,endnav"`, and it must not be `"e
0 commit comments