Skip to content

Commit

Permalink
Update Pattern block category and add documentation (#36144)
Browse files Browse the repository at this point in the history
* Update pattern category and add documentation.

* Fix typo

Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>

* Add link to i18n docs.

* Update docs/how-to-guides/themes/block-theme-overview.md

Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>

* Update docs/how-to-guides/themes/block-theme-overview.md

Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>

Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>
Co-authored-by: Ben Dwyer <ben@scruffian.com>
  • Loading branch information
3 people authored and noisysocks committed Nov 28, 2021
1 parent 518e7a2 commit 4191997
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions docs/how-to-guides/themes/block-theme-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ As we're still early in the process, the number of blocks specifically dedicated
- Query
- Query Loop
- Query Pagination
- Pattern
- Post Title
- Post Content
- Post Author
Expand All @@ -124,6 +125,46 @@ As we're still early in the process, the number of blocks specifically dedicated

One of the most important aspects of themes (if not the most important) is the styling. While initially you'll be able to provide styles and enqueue them using the same hooks themes have always used, the [Global Styles](/docs/how-to-guides/themes/theme-json.md) effort will provide a scaffolding for adding many theme styles in the future.

## Internationalization (i18n)

A pattern block can be used to insert translatable content inside a block template. Since those files are php-based, there is a mechanism to mark strings for translation or supply dynamic URLs.

#### Example

Register a pattern:

```php
<?php
register_block_pattern(
'myblocktheme/wordpress-credit',
array(
'title' => __( 'Wordpress credit', 'myblocktheme' ),
'content' => '
<!-- wp:paragraph -->
<p>' .
sprintf(
/* Translators: WordPress link. */
esc_html__( 'Proudly Powered by %s', 'myblocktheme' ),
'<a href="' . esc_url( __( 'https://wordpress.org', 'myblocktheme' ) ) . '" rel="nofollow">WordPress</a>'
) . '</p>
<!-- /wp:paragraph -->',
'inserter' => false
)
);
```

Load the pattern in a template or template part:

```html
<!-- wp:group -->
<div class="wp-block-group">
<!-- wp:pattern {"slug":"myblocktheme/wordpress-credit"} /-->
</div>
<!-- /wp:group -->
```

You can read more about [internationalization in WordPress here](https://developer.wordpress.org/apis/handbook/internationalization/).

## Classic Themes

Users of classic themes can also build custom block templates and use them in their Pages and Custom Post Types that support Page Templates.
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/pattern/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"apiVersion": 2,
"name": "core/pattern",
"title": "Pattern",
"category": "design",
"category": "theme",
"description": "Show a block pattern.",
"supports": {
"html": false,
Expand Down

0 comments on commit 4191997

Please sign in to comment.