Add a new block
Open the packages/Acme/etc/blocks.php file, and add a new block:
<?php
$config = [
Core_Block::TYPE => [
/* ... */
'banner' => [ // The block identifier
'class' => Acme_Block_Banner::class, // Optional
'caption' => 'Welcome to MageWork!',
],
/* ... */
],
];
Create a new class: packages/Acme/Block/Banner.php
<?php
declare(strict_types=1);
class Acme_Block_Banner extends Core_Block
{
public function execute(): void
{
$this->setImage('media/banner.png');
}
public function canShow(): bool
{
return true;
}
}
Open any template file, example: packages/Acme/template/page.phtml
<?= $this->getBlock('block/banner', ['alt' => 'My Banner'], 'banner') ?>
Finally, create the template file: packages/Acme/template/block/banner.phtml
<?php /** @var Acme_Block_Banner $this */ ?>
<?php if ($this->canShow()): ?>
<figure>
<img src="<?= $this->getAssetUrl($this->getImage()) ?>" alt="<?= App::escapeHtmlAttr($this->getAlt()) ?>" />
<figcaption><?= App::escapeHtml($this->getCaption()) ?></figcaption>
</figure>
<?php endif; ?>
- Installation
- Configuration
- Add a new package
- Add a new HTML page
- Serve any type of file
- Rewrite a route
- Add a new block
- Data assignment
- Objects and class fallback
- Database
- Console Commands
- Framework tools
- Custom shared libraries
- External libraries with composer
- Templating best practices
- Forms
- Captcha
- Write content in Markdown
- Static Site Generator