Welcome

Of course, one would use an API-based Php-framework + something like REACT to render the stuff. Just playing around a bit, not sure where it leads to. Do not expect too much content here ;P

<?php

declare(strict_types=1);

namespace WebSite\Services\Pages;

use Website\Enity\Page;
use Website\Helper\Renderer;
use Doctrine\ORM\EntityManager;

final class PageRenderer
{
… private Renderer $renderer
… private EntityManager $entityManager

… public function __construct(
…… EntityManager $entityManager,
…… Renderer $renderer
… ) {
…… this->entitiyManager = $entityManager
…… this->renderer = $renderer
… }

… public function __invoke(string $pageIdentifier): void
… {
…… $pageEntity = $this->entityManager->getRepository(Page::class)->findOneBy([’name‘ => $pageIdentifer]);
…… $this->renderer->renderTitle($pageEntitiy->getHeadline());
…… foreach ($pageEntitiy->getBlocks() as $pageBlock) {
……… $this->renderer->renderBlock($pageBlock->getType(), $pageBlock->getContent(), $pageBlock->getReplacements());
…… }
… }
}

<?php

declare(strict_types=1);

namespace WebSite\Helper;

use Website\Enity\BlockType;

final class Renderer
{
… const PAGE_TITLE_CSS_CLASS = ‚page-title‘;

… public function renderTitle(string $pageTitle): void
… {
…… echo $this->getTagH1($pageTitle, self::PAGE_TITLE_CSS_CLASS);
… }

… public function renderBlock(
…… BlockType $blockType,
…… string $blockContent,
…… array $replacements,
… ): void {
…… [tbc]
…… }
… }

… public function getTagH1(
…… string $headline,
…… string $className = null
… ): string {
…… $headline = trim($headline);
…… if (empty($headline)) {
………… return “;
…… }
…… if (null === $className) {
………… return sprintf(‚<h1>%s</h1>‘, $headline);
…… }
…… return sprintf(‚<h1 class=“%s“>%s</h1>‘, $headline, trim($className));
…… }
… }
}