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
- Localized: Yes (`title`, `description`, and `keywords` of each variation only)
433
433
- Property: `variations`
@@ -454,6 +454,48 @@ Block Variations is the API that allows a block to have similar versions of it,
454
454
455
455
_Note: In JavaScript you can provide a function for the `isActive` property, and a React element for the `icon`. In the `block.json` file both only support strings_
456
456
457
+
Starting with version 6.7, it is possible to specify a PHP file in `block.json` that generates the list of block variations on the server side:
458
+
459
+
```json
460
+
{ "variations": "file:./variations.php" }
461
+
```
462
+
463
+
That PHP file is expected to `return` an array that contains the block variations. Strings found in the variations returned from the PHP file will not be localized automatically; instead, use the `__()` function as usual.
464
+
465
+
For example:
466
+
467
+
```php
468
+
<?php
469
+
// Generate variations for a Social Icon kind of block.
470
+
471
+
return array(
472
+
array(
473
+
'isDefault' => true,
474
+
'name' => 'wordpress',
475
+
'title' => 'WordPress',
476
+
'icon' => 'wordpress',
477
+
'attributes' => array(
478
+
'service' => 'wordpress',
479
+
),
480
+
'isActive' => array( 'service' )
481
+
),
482
+
array(
483
+
'name' => 'mail',
484
+
'title' => __( 'Mail' ),
485
+
'keywords' => array(
486
+
__( 'email' ),
487
+
__( 'e-mail' )
488
+
),
489
+
'icon' => 'mail',
490
+
'attributes' => array(
491
+
'service' => 'mail',
492
+
),
493
+
'isActive' => array( 'mail' )
494
+
),
495
+
);
496
+
497
+
```
498
+
457
499
See [the variations documentation](/docs/reference-guides/block-api/block-variations.md) for more details.
// Nested children of the container with left and right padding that are not wide or full aligned do not get padding, unless they are direct children of an alignfull flow container.
// Nested children of the container with left and right padding that are not full aligned do not get padding, unless they are direct children of an alignfull flow container.
0 commit comments