Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pattern block category and add documentation #36144

Merged
merged 5 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we highlight this flag (inserter=>false) that hides such patterns from the list of displayed patterns in inserter/explorer. etc...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would be super helpful

)
);
```

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