Skip to content

Commit faed87b

Browse files
authored
Merge pull request #143 from infinum/feature/blog-posts
Feature/blog posts
2 parents e11a83b + 6911e39 commit faed87b

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Adding components and blocks with WP-CLI
3+
description: This blog post covers how to use our WP CLI commands for adding components and blocks into your project.
4+
slug: adding-blocks-wpcli
5+
authors: iobrado
6+
date: 2022-03-14
7+
tags: [eightshift, boilerplate, wpcli, components, blocks]
8+
hide_table_of_contents: false
9+
---
10+
Although there are a few basic blocks available after creating a project, there are a lot more blocks available in the dev kit. However, you have to add them to your project using WP-CLI (the simplest method). To see the complete list of available components and blocks, visit our [Storybook](https://infinum.github.io/eightshift-docs/storybook/).
11+
12+
These can be used out-of-the-box, but also as a good starting point if you need similar blocks in your projects. It will also speed up your development time since you don't have to build everything from scratch.
13+
14+
<!--truncate-->
15+
### Storybook
16+
17+
Storybook allows you to preview how the components and blocks look and which options they have available. Since Storybook is interactive, you can try out most of the options. Think of it as a catalog with all custom blocks we've built and made ready for public use.
18+
19+
Each entry in Storybook should have documentation that explains the block in more detail, along with implementation instructions. Before using any block, be sure to check `Dependencies` section. Although `Implementation` section lists all the necessary WP-CLI commands required to use a specific block or a component, it is recommended to check if you have the required dependencies ready in your theme.
20+
21+
### WP-CLI commands
22+
23+
If you've read our [Initial Setup](/blog/initial-setup) post, you're already familiar with our custom WP-CLI commands. For implementing additional components, we have `wp boilerplate use_component` command. For blocks, we have `wp_boilerplate use_block` command.
24+
25+
### Adding new component and block in our project
26+
27+
Let's say we need a Quote block in our project. After going through the documentation of the Quote block, we see that we have one dependency, and that is the Quote component. So, to make Quote block available in our project, we need two WP-CLI commands:
28+
29+
```bash
30+
wp boilerplate use_component --name=quote
31+
wp boilerplate use_block --name=quote
32+
```
33+
34+
You should do the commands in this order because Quote component doesn't have any dependencies, while the Quote block has one dependency, and that is Quote component. Otherwise, you will get an error. After entering these commands, run `npm start` again to make sure everything works properly.
35+
36+
The Quote block is now ready to use and available in your blocks list. You may use it as-is, or you may want to expand its functionalities with some additional attributes. More about that will be covered in the next blog post.
37+
38+
### Using Example block
39+
40+
If you want to build a block almost from scratch, you can use our Example block. This is a very simple block that generates all necessary files with some example options. To add an Example block to your project, use the following WP-CLI command:
41+
```bash
42+
wp boilerplate use_block --name=example
43+
```
44+
Since our blocks use a predefined structure to make everything register automatically, adding Example block with WP-CLI will generate all required files. After it's added, feel free to rename the folder, as well as files with the name of your block and start modifying all the files. Simply replace "example" with the name of your block.
45+
46+
### Further reading
47+
Our documentation has all this covered in a lot more detail, so if you would like to better understand the structure of our blocks and components, here are some chapters covering these topics:
48+
- [Structure](/docs/basics/the-structure)
49+
- [Block Structure](/docs/basics/block-structure)
50+
- [Component Structure](/docs/basics/blocks-component-structure)

website/docs/legacy/v4/guides/menu.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ To add the custom menu, you must provide an array for custom menu locations as e
1313

1414
```js
1515
/**
16-
* Return all menu poistions
17-
*
18-
* @return array Of menu positions with name and slug.
19-
*
20-
* @since 1.0.0
21-
*/
22-
public function get_menu_positions() : array {
23-
return [
24-
'header_main_default' => esc_html__( 'Header Main', 'eightshift-boilerplate' ),
25-
];
26-
}
16+
* Return all menu positions
17+
*
18+
* @return array<string> Menu positions with slug => name structure.
19+
*/
20+
public function getMenuPositions(): array
21+
{
22+
return [
23+
'header_main_nav' => \esc_html__('Main Menu', 'eightshift-boilerplate'),
24+
];
25+
}
2726
```
2827

2928
## BEM Menu helper
@@ -35,7 +34,7 @@ To use it just call this helper in your template.
3534
```js
3635
use Eightshift_Libs\Menu\Menu;
3736

38-
Menu::bem_menu( 'header_main_default', 'main-navigation' );
37+
Menu::bemMenu( 'header_main_nav', 'main-navigation' );
3938
```
4039

4140
You can also provide multiple parameters to the helper. All the details are [found here](https://github.com/infinum/eightshift-libs/blob/404aeab50beef38f788c864d7c0312858b097e81/src/menu/class-menu.php#L69).

0 commit comments

Comments
 (0)