MageWork

Back to home

Add a new page

Open the packages/acme/etc/pages.php file, and add a new page:

<?php

$config = [
    'acme' => [
        Core_Page::TYPE => [
            /* ... */
            '/contact.html' => [
                'class' => Acme_Page_Contact::class, // Optional
                'content' => 'content/contact',
                'title' => 'Contact',
                'description' => 'Contact our team',
                'telephone' => '+33 610506070',
            ],
            /* ... */
        ],
    ],
];

Warning:

Create a new class: packages/acme/app/Acme/Page/Index.php

<?php

declare(strict_types=1);

class Acme_Page_Contact extends Core_Page
{
    public function execute(): void
    {
        $this->setAddress("459 Walker Cape, Powellchester, OL16 3NA");
    }
}

The execute method is called before template rendering. It allows you to implement the code logic and inject data into the template.

Finally, create the template file: packages/acme/template/content/contact.phtml

<h2>Contact us!</h2>

<p>Telephone: <?= App::escapeHtml($this->getTelephone()) ?></p>
<p>Address: <?= App::escapeHtml($this->getAddress()) ?></p>

Access to /contact.html in your browser!