Skip to content

Commit 04d1a72

Browse files
authored
Merge pull request #146 from infinum/feature/blog-posts
Feature/blog posts
2 parents 1852344 + 6911e39 commit 04d1a72

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
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)

0 commit comments

Comments
 (0)