@@ -53,31 +53,41 @@ you to quickly create a "Quiz" to find the most suitable element.
53
53
54
54
## Requirements
55
55
56
- This plugin requires Craft CMS 3.3 .0 or later.
56
+ This plugin requires Craft CMS 3.4 .0 or later.
57
57
58
58
## Using Characteristic
59
59
60
60
### The Drilldown Helper
61
61
``` twig
62
+ {# Any arbitrary base element query #}
62
63
{% set query = craft.entries.section('restaurants') %}
63
- {% set drilldown = craft.characteristic.drilldown('restaurants', query) %}
64
+
65
+ {# Create an instance of the drilldown helper for the characteristic group with the handle `restaurantCharacteristics` #}
66
+ {% set drilldown = craft.characteristic.drilldown('restaurantCharacteristics', query) %}
64
67
65
68
{% set state = drilldown.state %}
66
69
67
70
{% set current = drilldown.currentCharacteristic %}
68
71
72
+ {# Get a text field called characteristicDescription off of the characteristic #}
69
73
<h2>{{ current.characteristicDescription }}</h2>
70
74
75
+ {# Get all of the options available for the current characteristic #}
71
76
{% set options = drilldown.currentOptions.all() %}
72
77
73
78
<ul>
74
79
{% for option in options %}
80
+ {# Use the applyToDrilldownState method to create a URL for this value based on the current state #}
75
81
<li><a href="{{ option.applyToDrilldownState(state).url }}">{{ option.value }}</a></li>
82
+
83
+ {# Grab a featuredImage Asset field off of the option #}
76
84
{% if option.featuredImage.exists() %}
77
85
<img src="{{ option.featuredImage.one().url }}" />
78
86
{% endif %}
79
87
{% endfor %}
80
88
<hr>
89
+
90
+ {# Optional URL to skip the question with picking an answer #}
81
91
<a href="{{ drilldown.skipUrl() }}">Skip Question</a>
82
92
</ul>
83
93
@@ -94,20 +104,9 @@ This plugin requires Craft CMS 3.3.0 or later.
94
104
```
95
105
96
106
### The characteristics field
97
- The field returns a CharacteristicLinkQuery pre-configured for the
107
+ The field returns a CharacteristicLinkBlockQuery pre-configured for the
98
108
element.
99
109
100
- #### Get a single characteristic's value
101
- ``` twig
102
- <ul>
103
- {# Loop over restaurants showing the selected price Characteristic #}
104
- {% for restaurant in query.all() %}
105
- {% set price = restaurant.restaurantAttributes.characteristic('price').with(['value']).all() %}
106
- <li>{{ restaurant.title }} - {{ price ? price[0].value.value : 'No Data' }}</li>
107
- {% endfor %}
108
- </ul>
109
- ```
110
-
111
110
#### Get all characteristics on an entry and show them as a table
112
111
``` twig
113
112
<table class="table-auto">
@@ -118,41 +117,19 @@ element.
118
117
</tr>
119
118
</thead>
120
119
<tbody>
121
- {# We have to group our characteristics by something (title), otherwise they will show a distinct table rows #}
122
- {% set attributes = entry.restaurantAttributes.all()|group(v => v.characteristic.title ) %}
123
- {% for title, values in attributes %}
120
+
121
+ {% set blocks = entry.restaurantAttributes.all() %}
122
+ {% for block in blocks %}
124
123
<tr>
125
- <td class="border px-4 py-2">{{ title }}</td>
124
+ <td class="border px-4 py-2">{{ block.characteristic. title }}</td>
126
125
{# We're going to create a string out of the characteristic value's text value #}
127
- <td class="border px-4 py-2">{{ values|column('value. value')|join(', ') }}</td>
126
+ <td class="border px-4 py-2">{{ block. values.all() |column('value')|join(', ') }}</td>
128
127
</tr>
129
128
{% endfor %}
130
129
</tbody>
131
130
</table>
132
131
```
133
132
134
- ### The characteristic attribute
135
- Characteristic will inject some attributes into your elements to make
136
- querying characteristics easier! Take care to ensure you don't have any
137
- fields with the same handles as these.
138
-
139
- - ` characteristics ` returns a CharacteristicQuery configured to return
140
- only those related to the source element.
141
-
142
- ``` twig
143
- <ul>
144
- {% for product in craft.entries.section('products').all() %}
145
- <li>{{product.title}}</li>
146
- <ul>
147
- {% for characteristic in product.characteristics.all() %}
148
- {# We could use .values() without a parameter if we wanted to get all possible values indiscriminately #}
149
- <li>{{ characteristic.title }} - {{ characteristic.values(restaurant).all()|column('value')|join(', ') }}</li>
150
- {% endfor %}
151
- </ul>
152
- {% endfor %}
153
- </ul>
154
- ```
155
-
156
133
### Querying for elements
157
134
There are a few different ways to query for elements with certain characteristics.
158
135
@@ -182,9 +159,9 @@ Characteristic Value is relative to a specific Characteristic. A
182
159
Characteristic Value has a ` value ` attribute that is a text string that
183
160
is unique to each Characteristic. For example: "Yes", "No", "1.25".
184
161
185
- #### Characteristic Link
162
+ #### Characteristic Link Block
186
163
An Element that contains the linkage between a particular
187
- Characteristic, a Characteristic Value , the field it was created from,
164
+ Characteristic, a number of Characteristic Values , the field it was created from,
188
165
as well as the element its attached to.
189
166
190
167
#### Characteristic Field
0 commit comments