Skip to content

Commit 6868454

Browse files
authored
Merge pull request #744 from ExpressionEngine/feature/7.x/options-fts-variables
Added `{index}` and `{total_items}` variables to options fieldtypes
2 parents 853aa78 + ff5b61e commit 6868454

3 files changed

Lines changed: 58 additions & 17 deletions

File tree

docs/fieldtypes/checkboxes.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
[TOC]
1313

14-
Checkboxes allow publishers to choose multiple items from a list.
14+
Checkboxes allow publishers to choose multiple items from a list.
1515

1616
![multiselect field](_images/cp-field-multiselect.png)
1717

@@ -49,7 +49,7 @@ You can use a single variable for Checkboxes to render a comma-separated list of
4949

5050
### Variable Pair
5151

52-
Using a variable pair, allows for customization of the output.
52+
Using a variable pair of field name, allows for customization of the output.
5353

5454
{field_name}
5555
{item}<br>
@@ -63,7 +63,18 @@ Two
6363
Three
6464
```
6565

66-
By default, `{item}` will render the item's value. To access the value and label separately, simply add a `:value` or `:label` modifier to the `{item}` variable:
66+
The following variables are available inside field's tags pair:
67+
68+
| Variable | Description |
69+
| --------------- | --------------------------------------------------- |
70+
| `{item}` | Label of selected item |
71+
| `{item:label}` | Label of selected item |
72+
| `{item:value}` | Value of selected item |
73+
| `{count}` | Counter for each of selected items, starting with 1 |
74+
| `{index}` | Counter for each of selected items, starting with 0 |
75+
| `{total_items}` | Total number of selected items |
76+
77+
By default, `{item}` will render the item's label. To access the value and label separately, simply add a `:value` or `:label` modifier to the `{item}` variable:
6778

6879
{field_name}
6980
Value: {item}<br> {!-- 1 --}
@@ -88,17 +99,19 @@ Given that the selection option is 2/Two:
8899

89100
TIP: **Tip:** It is recommended that you use the value in conditionals, as it typically will not change over time. That way, if you ever need to change the wording, spelling, or even casing of labels in your publish/edit UI, you will not need to modify your templates.
90101

91-
TIP: **Tip:** Checkboxes, Multiselect and Selectable Buttons all default to showing the label. Radio Buttons and Selects default to showing the value.
102+
TIP: **Tip:** Checkboxes, Multiselect and Selectable Buttons all default to showing the label. Radio Buttons and Selects default to showing the value.
103+
104+
### Parameters
92105

93-
### Limit Parameter
106+
#### `limit`
94107

95108
This parameter limits the number of selected items output by the tag. It works for both the single variable, as well as the tag pair.
96109

97110
```
98111
{field_name limit="2"} {!-- One,Two --}
99112
```
100113

101-
### Markup Parameter
114+
#### `markup`
102115

103116
As a single tag, a checkbox will display a comma separated list of values. If you want an HTML list, you can use markup="ul" or markup="ol" to change the output to the equivalent html list
104117

@@ -112,7 +125,7 @@ Which will render as
112125
<li>Orange</li>
113126
</ul>
114127

115-
### Backspace Parameter
128+
#### `backspace`
116129

117130
When used as a tag pair, checkboxes are a looping pair. Backspacing removes characters (including spaces and line breaks) from the last iteration of the loop. For example, if you put a `<br>` tag after each item you'll have this
118131

docs/fieldtypes/multiselect.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
[TOC]
1313

14-
Multi Select Fields allow publishers to choose multiple items from a list.
14+
Multi Select Fields allow publishers to choose multiple items from a list.
1515

1616
![multiselect field](_images/cp-field-multiselect.png)
1717

@@ -63,7 +63,19 @@ Two
6363
Three
6464
```
6565

66-
By default, `{item}` will render the item's value. To access the value and label separately, simply add a `:value` or `:label` modifier to the `{item}` variable:
66+
67+
The following variables are available inside field's tags pair:
68+
69+
| Variable | Description |
70+
| --------------- | --------------------------------------------------- |
71+
| `{item}` | Label of selected item |
72+
| `{item:label}` | Label of selected item |
73+
| `{item:value}` | Value of selected item |
74+
| `{count}` | Counter for each of selected items, starting with 1 |
75+
| `{index}` | Counter for each of selected items, starting with 0 |
76+
| `{total_items}` | Total number of selected items |
77+
78+
By default, `{item}` will render the item's label. To access the value and label separately, simply add a `:value` or `:label` modifier to the `{item}` variable:
6779

6880
{field_name}
6981
Value: {item}<br> {!-- One --}
@@ -88,17 +100,19 @@ Given that the selection option is 2/Two:
88100

89101
TIP: **Tip:** It is recommended that you use the value in conditionals, as it typically will not change over time. That way, if you ever need to change the wording, spelling, or even casing of labels in your publish/edit UI, you will not need to modify your templates.
90102

91-
TIP: **Tip:** Checkboxes, Multiselect and Selectable Buttons all default to showing the label. Radio Buttons and Selects default to showing the value.
103+
TIP: **Tip:** Checkboxes, Multiselect and Selectable Buttons all default to showing the label. Radio Buttons and Selects default to showing the value.
104+
105+
### Parameters
92106

93-
### Limit Parameter
107+
#### `limit`
94108

95109
This parameter limits the number of selected items output by the tag. It works for both the single variable, as well as the tag pair.
96110

97111
```
98112
{field_name limit="2"} {!-- One,Two --}
99113
```
100114

101-
### Markup Parameter
115+
#### `markup`
102116

103117
As a single tag, a multi select will display a comma separated list of values. If you want an HTML list, you can use markup="ul" or markup="ol" to change the output to the equivalent html list
104118

@@ -112,7 +126,7 @@ Which will render as
112126
<li>Orange</li>
113127
</ul>
114128

115-
### Backspace Parameter
129+
#### `backspace`
116130

117131
When used as a tag pair, Multiselect are a looping pair. Backspacing removes characters (including spaces and line breaks) from the last iteration of the loop. For example, if you put a `<br>` tag after each item you'll have this
118132

docs/fieldtypes/selectable-buttons.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,19 @@ When allowing multiple items to be selected, Selectable Buttons will usually be
6060
{item}<br>
6161
{/field_name}
6262

63-
By default, `{item}` will render the item's value. To access the value and label separately, simply add a `:value` or `:label` modifier to the `{item}` variable:
63+
64+
The following variables are available inside field's tags pair:
65+
66+
| Variable | Description |
67+
| --------------- | --------------------------------------------------- |
68+
| `{item}` | Label of selected item |
69+
| `{item:label}` | Label of selected item |
70+
| `{item:value}` | Value of selected item |
71+
| `{count}` | Counter for each of selected items, starting with 1 |
72+
| `{index}` | Counter for each of selected items, starting with 0 |
73+
| `{total_items}` | Total number of selected items |
74+
75+
By default, `{item}` will render the item's label. To access the value and label separately, simply add a `:value` or `:label` modifier to the `{item}` variable:
6476

6577
{field_name}
6678
Value: {item}<br>
@@ -98,11 +110,13 @@ TIP: **Tip:** Checkboxes, Multiselect and Selectable Buttons all default to show
98110

99111
NOTE: **NOTE:** For Select fields used in [Custom Member Fields](control-panel/member-manager.md#custom-member-fields) and [Category Group Details Tab](control-panel/categories.md#details-tab), the modifiers are not currently available in conditionals, and _must_ be based on the value, e.g. `{if some_cat_field == 2}`
100112

101-
### Limit Parameter
113+
### Parameters
114+
115+
#### `limit`
102116

103117
This parameter limits the number of selected items output by the tag. It works for both the single variable, as well as the tag pair.
104118

105-
### Markup Parameter
119+
#### `markup`
106120

107121
When allowing for multiple selections, a single tag will display a comma separated list of values. If you want an HTML list, you can use markup="ul" or markup="ol" to change the output to the equivalent html list
108122

@@ -116,7 +130,7 @@ Which will render as
116130
<li>Orange</li>
117131
</ul>
118132

119-
### Backspace Parameter
133+
#### `backspace`
120134

121135
Backspacing removes characters (including spaces and line breaks) from the last iteration of the loop when using a variable pair. For example, if you put a `<br>` tag after each item you'll have this
122136

0 commit comments

Comments
 (0)