Skip to content

Commit 16d6815

Browse files
authored
docs: fix typos and replace accordions with tabs for clarity (#227)
2 parents e2f0433 + 1827be1 commit 16d6815

File tree

1 file changed

+38
-58
lines changed

1 file changed

+38
-58
lines changed

docs/grid/field_types.md

Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
Field Types
2-
===========
1+
# Field Types
32

43
This is the list of built-in field types.
54

6-
String
7-
------
5+
## String
86

9-
Simplest column type, which basically renders the value at given path as
10-
a string.
7+
The simplest column type, which displays the value at the specified path as plain text.
118

129
By default, it uses the name of the field, but you can specify a different path if needed. For example:
1310

14-
<details open><summary>Yaml</summary>
15-
11+
{% tabs %}
12+
{% tab title="YAML" %}
1613
{% code title="config/packages/sylius_grid.yaml" lineNumbers="true" %}
1714
```yaml
1815
sylius_grid:
@@ -25,11 +22,8 @@ sylius_grid:
2522
path: contactDetails.email
2623
```
2724
{% endcode %}
28-
29-
</details>
30-
31-
<details open><summary>PHP</summary>
32-
25+
{% endtab %}
26+
{% tab title="PHP" %}
3327
{% code title="config/packages/sylius_grid.php" lineNumbers="true" %}
3428
```php
3529
<?php
@@ -91,24 +85,21 @@ final class UserGrid extends AbstractGrid implements ResourceAwareGridInterface
9185
}
9286
```
9387
{% endcode %}
88+
{% endtab %}
89+
{% endtabs %}
9490

95-
</details>
91+
This configuration will display the value of `$user->getContactDetails()->getEmail()`.
9692

97-
This configuration will display the value from
98-
`$user->getContactDetails()->getEmail()`.
93+
## DateTime
9994

100-
DateTime
101-
--------
102-
103-
This column type works exactly the same way as *string*, but expects a
104-
*DateTime* instance and outputs a formatted date and time string.
95+
This column type works exactly the same way as *StringField*, but expects a *DateTime* instance and outputs a formatted date and time string.
10596

10697
Available options:
107-
* `format` - default is `Y:m:d H:i:s`, you can modify it with any supported format (see https://www.php.net/manual/en/datetime.format.php)
108-
* `timezone` - default is `%sylius_grid.timezone%` parameter, null if such a parameter does not exist, you can modify it with any supported timezone (see https://www.php.net/manual/en/timezones.php)
109-
110-
<details open><summary>Yaml</summary>
98+
* `format` - defaults to `Y:m:d H:i:s`, you can set it to any supported format (see https://www.php.net/manual/en/datetime.format.php)
99+
* `timezone` - defaults to `%sylius_grid.timezone%` parameter, null if such a parameter does not exist, you can set it to any supported timezone (see https://www.php.net/manual/en/timezones.php)
111100

101+
{% tabs %}
102+
{% tab title="YAML" %}
112103
{% code title="config/packages/sylius_grid.yaml" lineNumbers="true" %}
113104
```yaml
114105
sylius_grid:
@@ -123,11 +114,9 @@ sylius_grid:
123114
timezone: null
124115
```
125116
{% endcode %}
117+
{% endtab %}
126118
127-
</details>
128-
129-
<details open><summary>PHP</summary>
130-
119+
{% tab title="PHP" %}
131120
{% code title="config/packages/sylius_grid.php" lineNumbers="true" %}
132121
```php
133122
<?php
@@ -187,15 +176,12 @@ final class UserGrid extends AbstractGrid implements ResourceAwareGridInterface
187176
}
188177
```
189178
{% endcode %}
179+
{% endtab %}
180+
{% endtabs %}
190181

191-
</details>
182+
{% hint style="warning" %}
183+
If you want to call the `setOptions` function, you must pass both `'format'` and `'timezone'` as arguments again. Otherwise, they will be unset.
192184

193-
### *Warning*
194-
195-
You have to pass `'format'` and `'timezone'` again if you want to call the `setOptions` function.
196-
Otherwise, it will be unset:
197-
198-
Example:
199185
{% code %}
200186
```php
201187
$field->setOptions([
@@ -206,17 +192,15 @@ $field->setOptions([
206192
]);
207193
```
208194
{% endcode %}
195+
{% endhint %}
209196

210-
Twig (*twig*)
211-
-------------
197+
## Twig
212198

213-
The Twig column type is the most flexible one, because it
214-
delegates the logic of rendering the value to the Twig templating engine.
215-
You just have to specify the template and it will be rendered with the
216-
`data` variable available to you.
217-
218-
<details open><summary>Yaml</summary>
199+
The Twig column type is the most flexible one, because it delegates the logic of rendering the value to the Twig templating engine.
200+
First, you must specify the template you want to render.
219201

202+
{% tabs %}
203+
{% tab title="YAML" %}
220204
{% code title="config/packages/sylius_grid.yaml" lineNumbers="true" %}
221205
```yaml
222206
sylius_grid:
@@ -230,11 +214,9 @@ sylius_grid:
230214
template: "@Grid/Column/_prettyName.html.twig"
231215
```
232216
{% endcode %}
217+
{% endtab %}
233218
234-
</details>
235-
236-
<details open><summary>PHP</summary>
237-
219+
{% tab title="PHP" %}
238220
{% code title="config/packages/sylius_grid.php" lineNumbers="true" %}
239221
```php
240222
<?php
@@ -294,20 +276,19 @@ final class UserGrid extends AbstractGrid implements ResourceAwareGridInterface
294276
}
295277
```
296278
{% endcode %}
279+
{% endtab %}
280+
{% endtabs %}
297281

298-
</details>
299-
300-
In the `@Grid/Column/_prettyName.html.twig` template, you just need to
301-
render the value. For example:
282+
Then, within the template, you can render the field's value via the `data` variable.
302283

303-
{% code %}
284+
{% code title="@Grid/Column/_prettyName.html.twig" %}
304285
```twig
305286
<strong>{{ data }}</strong>
306287
```
307288
{% endcode %}
308289

309290
If you wish to render more complex grid fields, just redefine the path of
310-
the field to root – `path: .` and then you can access all
291+
the field to root in your grid `path: .` and then you can access all
311292
attributes of the object instance:
312293

313294
{% code %}
@@ -317,11 +298,9 @@ attributes of the object instance:
317298
```
318299
{% endcode %}
319300

320-
### *Warning*
321-
322-
You have to pass the `'template'` option again if you want to call the `setOptions` function. Otherwise, it will be unset:
301+
{% hint style="warning" %}
302+
If you want to call the `setOptions` function, you must pass `'template'` as an argument again. Otherwise, it will be unset.
323303

324-
Example:
325304
{% code %}
326305
```php
327306
$field->setOptions([
@@ -331,3 +310,4 @@ $field->setOptions([
331310
]);
332311
```
333312
{% endcode %}
313+
{% endhint %}

0 commit comments

Comments
 (0)