Also bleiben wir mal bei dem Beispiel auf https://docs.contao.org/dev/guides/f...t-controllers/
Ich habe in /src/Controller/FrontendModule/AppExampleController.php folgendes:
PHP-Code:
<?php
// src/Controller/FrontendModule/AppExampleController.php
namespace App\Controller\FrontendModule;
use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
use Contao\ModuleModel;
use Contao\ModuleNewsList;
use Symfony\Component\HttpFoundation\Response;
/**
* @FrontendModule(category="news")
*/
class AppExampleController extends ModuleNewsList
{
public function __construct() {}
public function __invoke(ModuleModel $model, string $section): Response
{
parent::__construct($model, $section);
return new Response($this->generate());
}
/**
* Generate the module
*/
protected function compile()
{
$this->Template->hallo = "Hallo Welt!";
parent::compile();
}
}
Und in /templates/mod_newslist.html5
PHP-Code:
<?php $this->extend('block_unsearchable'); ?>
<?php $this->block('content'); ?>
Test: <?= $this->hallo ?>
<?php if (empty($this->articles)): ?>
<p class="empty"><?= $this->empty ?></p>
<?php else: ?>
<?= implode('', $this->articles) ?>
<?= $this->pagination ?>
<?php endif; ?>
<?php $this->endblock(); ?>
Die composer.json sieht so aus (da habe ich nichts geändert):
PHP-Code:
{
"name": "contao/managed-edition",
"type": "project",
"description": "Contao Managed Edition",
"license": "LGPL-3.0-or-later",
"require": {
"contao/conflicts": "*@dev",
"contao/manager-bundle": "4.9.*",
"contao/news-bundle": "^4.9",
"madeyourday/contao-rocksolid-custom-elements": "^2.3",
"terminal42/contao-easy_themes": "^2.2"
},
"conflict": {
"contao-components/installer": "<1.3"
},
"extra": {
"contao-component-dir": "assets"
},
"scripts": {
"post-install-cmd": [
"Contao\\ManagerBundle\\Composer\\ScriptHandler::initializeApplication"
],
"post-update-cmd": [
"Contao\\ManagerBundle\\Composer\\ScriptHandler::initializeApplication"
]
}
}
Im Frontend sehe ich natürlich Test:, aber das Hallo Welt! wird nicht ausgegeben…
Lesezeichen