Creating Blocks Instrumented for use with the Universal Editor create-block
Learn how to create blocks instrumented for use with the Universal Editor in WYSIWYG authoring with Edge Delivery Services projects.
Prerequisites prerequisites
This guide provides step-by-step instructions for how to create blocks instrumented for the Universal Editor in WYSIWYG authoring with Edge Delivery Services projects. It covers adding components, loading component definitions in the Universal Editor, publishing pages, implementing block decoration and styles, bringing the changes to production, and verifying them. Upon completing this guide, you can create and deploy a new block for your own project.
This guide necessarily requires existing knowledge of WYSIWYG authoring with Edge Delivery Services projects as well as the Universal Editor. Before beginning this guide, you should already have access to Edge Delivery Services and be familiar with its basics including:
- You have completed the Edge Delivery Service tutorial.
- You have access to an AEM Cloud Service sandbox.
- You have enabled the Universal Editor on the same sandbox environment.
- You have completed the Developer Getting Started Guide for WYSIWYG authoring with Edge Delivery Services guide.
This guide builds on the work done in the Developer Getting Started Guide for WYSIWYG authoring with Edge Delivery Services guide.
Adding a New Block to Your Project add-block
In this guide, you will build a block to render a memorable quote on your page.
To simplify this example, all changes are made to the main
branch of the project repository. Of course for your actual project, you should follow development best practices by developing on a different branch and reviewing all changes via pull request before merging to main
.
Adobe recommends that you develop blocks in a three-phased approach:
- Create the definition and model for the block, review it, and bring it to production.
- Create content with the new block.
- Implement the decoration and styles for the new block.
The following quote block example follows this approach.
Create Block Definition and Model create-block-model
1. Clone the GitHub project locally that you created in the Developer Getting Started Guide for WYSIWYG authoring with Edge Delivery Services guide and open it in an editor of your choice.
- Microsoft Code is used here for illustrative purposes.
2. Edit the component-definition.json
file at the root of the project and add the following definition for your new quote block and save the file.
code language-json |
---|
|
3. Edit the component-models.json
file at the root of the project and add the following model definition for your new quote block and save the file.
- Please see the document Content Modeling for WYSIWYG authoring with Edge Delivery Services Projects for more information about what is important to consider when creating content models.
code language-json |
---|
|
4. Edit the component-filters.json
file at the root of the project and add the quote block to the filter definition to allow the block to be added to any section and save the file.
code language-json |
---|
|
5. Using git, commit these changes to your main
branch.
- Committing to
main
is for illustrative purposes only. Follow best practices and use a pull request for actual project work.
Create Content with the Block create-content
Now that your basic quote block is defined and committed to the sample project, you can add a quote block to an existing page.
-
In a browser, sign into AEM as a Cloud Service. Using the Sites console, navigate to the site that you created in the Developer Getting Started Guide for WYSIWYG authoring with Edge Delivery Services guide and select a page.
- In this case,
index
is used for illustrative purposes.
- In this case,
-
Tap or click Edit in the toolbar of the console and the Universal Editor opens.
- In order to load the page, you may need to tap or click Sign in with Adobe to authenticate to AEM in the Universal Editor.
-
In the Universal Editor, select a section. In the properties panel, tap or click the Add icon and then select your new Quote block from the menu.
- The Add icon is a plus symbol.
- You know that you have selected a section if the blue outline of the selected object has a tab labeled Section.
- In this example, tapping or clicking slightly above the Lorem Ipsum heading selects a section containing the heading and lorem ipsum text.
-
The page is reloaded and the quote block is added to the bottom of the selected section with the default content specified in the
component-definitions.json
file.- The quote block can be selected and edited as any other block either in-place or in the properties panel.
- Styling is be applied in a further step.
-
Once you are satisfied with the content of your quote, you can publish the page by tapping or clicking the Publish button in the toolbar of the Universal Editor.
-
Verify that the content was published by navigating to the published page. The link will be similar to
https://<branch>--<repo>--<owner>.aem.page
Style the Block style-block
Now that you have a working quote block you can apply styling to it.
1. Return to the editor for your project.
2. Create a quote
folder under the blocks
folder.
3. In the new quote
folder, add a quote.js
file to implement block decoration by adding the following JavaScript and save the file.
code language-javascript |
---|
|
4. In the quote
folder, add a quote.css
file to define the styling for the block by adding the following CSS code and save the file.
code language-css |
---|
|
5. Using git, commit these changes to your main
branch.
- Committing to
main
is for illustrative purposes only. Follow best practices and use a pull request for actual project work.
6. Return to your browser tab of the Universal Editor where you were editing the page of your project and reload the page to view your styled block.
7. See the now styled quote block on the page.
8. Verify that the changes were pushed to production by navigating to the published page. The link will be similar to https://<branch>--<repo>--<owner>.aem.page
Congratulations! You now have a fully working and styled quote block. You can use this example as a basis for designing your own project-specific blocks.
Block Options block-options
If you need a block to look or behave slightly differently based on certain circumstances, but not different enough to become a new block in itself, you can let authors choose from block options.
By adding a classes
property to the block, the property rendered in the table header for simple blocks, or as value list for items in a container block.
{
"id": "simpleMarquee",
"fields": [
{
"component": "text",
"valueType": "string",
"name": "marqueeText",
"value": "",
"label": "Marquee text",
"description": "The text you want shown in your marquee"
},
{
"component": "select",
"name": "classes",
"value": "",
"label": "Background Color",
"description": "The marquee background color",
"valueType": "string",
"options": [
{
"name": "Red",
"value": "bg-red"
},
{
"name": "Green",
"value": "bg-green"
},
{
"name": "Blue",
"value": "bg-blue"
}
]
}
]
}
Using Other Working Branches other-branches
This guide had you commit directly to the main
branch for simplicity’s sake. For experimentation in a sample repository, this is usually not an issue. For actual project work, you should follow development best practices by developing on a different branch and reviewing all changes via pull request before merging to main
.
When you are not developing on the main
branch, you can append ?ref=<branch>
in the Universal Editor location bar to load the page from your branch. <branch>
is the branch name as it would be used for your project’s preview or live URLs, e.g. https://<branch>--<repo>--<owner>.aem.page
.
Reusing Your Blocks for Document-Based Authoring reusing-blocks
You can use the blocks you create for WYSIWYG authoring using the Universal Editor for document-based authoring if you adhere to the same content model.
Please see the document Blocks for WYSIWYG and Document-Based Authoring for more information.
Next Steps next-steps
Now that you know how to create blocks, it is essential to understand how to model content in a semantic way to achieve a lean developer experience.
Please see the document Content Modeling for WYSIWYG authoring with Edge Delivery Services Projects to learn how content modeling works for WYSIWYG authoring with Edge Delivery Services projects.