Objectives & prerequisites
Objectives
- Create a new module called my_block_demo.
- Create a new block plugin.
Prerequisites
- Know that blocks are plugins, and have a specific namespace and matching directory structure.
- Basic understanding of a few concepts: plugins, annotations, attributes and docblocks.
Activity
- Create a new module named my_block_demo.
- Ensure it has a valid info file.
- Enable it via Manage > Extend
- Refer to "Creating a Module" for step-by-step instructions if necessary.
Hide hints
show hints
Activity
- Create a new block class named HelloBlock
- In the annotation, choose any id you think is appropriate; by convention it should start with the name of your module.
- The block should say "Hello world, I'm a block."
- Ensure the block works correctly by placing it in the sidebar region.
Hide hints
show hints
Troubleshooting
- Have you cleared the cache?
- If your block doesn't come up as an available block to assign to a region at Manage > Structure > Block Library, there's probably something wrong with your block class:
- Is your namespace correct?
- Does your class name match the file name?
- Have you added the DocBlock and annotation?
- Have you implemented the
getBlockId()andbuild()methods? - Have you checked everything for typos?