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
Copy file name to clipboardExpand all lines: README.md
+61-2Lines changed: 61 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,6 +130,16 @@ body {
130
130
131
131
During run time, this file will be compiled into regular CSS by replacing all the variables to their corresponding values by calling the 'value callback' function and passing the variable name (without the $ sign) to that function.
132
132
133
+
**Array variables (since 1.0.3)**
134
+
135
+
Version 1.0.3 added support for array subscripts, using a syntax similar to that of PHP. For example:
136
+
```css
137
+
body {
138
+
font-family: $font['font-family'];
139
+
}
140
+
```
141
+
The callback function should accept a second variable that will hold an array of subscript names. A more in-depth explanation can be found in the [Setting the Value Callback](#setting-the-value-callback) section.
142
+
133
143
Future releases may support a more compex syntax, so any suggestions are welcome. You can make a suggestion by creating an issue or submitting a pull request.
134
144
135
145
## Enqueueing Dynamic Stylesheets
@@ -176,8 +186,8 @@ In that case, we can tweak our callback function to return default values as wel
176
186
177
187
```php
178
188
$theme_mod_defaults = array(
179
-
'body_bg_color': '#fff',
180
-
'body_text_color': 'black'
189
+
'body_bg_color' => '#fff',
190
+
'body_text_color' => 'black'
181
191
);
182
192
183
193
function my_dynamic_css_callback( $var_name )
@@ -205,6 +215,55 @@ body {
205
215
}
206
216
```
207
217
218
+
**Array variables**
219
+
220
+
It is also possible to access array values using subscripts. An example dynamic CSS file may look like:
However, in this case the callback function is passed 2 parameters: one holding the variable name, and a second holding an array of subscript names. The second variable is always going to be an array since there may be more than one subscript (multidimensional arrays). To retrieve to array value, the subscripts array is to be looped through to get each subscript. For example:
231
+
232
+
```php
233
+
$theme_mod_defaults = array(
234
+
'body_bg_color' => '#fff',
235
+
'body_text_color' => 'black'
236
+
'font' => array(
237
+
'font-familiy' => 'Arial',
238
+
'font-size' => 14
239
+
)
240
+
);
241
+
242
+
function my_dynamic_css_callback( $var_name, $subscripts = null )
0 commit comments