Hallo, ich bin absolut neu im Umgang mit Contao. Ich habe mir die Docu durchgelesen, aber nicht wirklich gefunden wie man ein Template in einem Controller "lädt".
Ich würde gerne so etwas machen:
PHP-Code:
// src/Controller/ProductController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class ProductController extends AbstractController
{
public function index(): Response
{
// ...
// the `render()` method returns a `Response` object with the
// contents created by the template
return $this->render('product/index.html.twig', [
'category' => '...',
'promotions' => ['...', '...'],
]);
// the `renderView()` method only returns the contents created by the
// template, so you can use those contents later in a `Response` object
$contents = $this->renderView('product/index.html.twig', [
'category' => '...',
'promotions' => ['...', '...'],
]);
return new Response($contents);
}
}
Da es in Contao keine Twig templates gibt sondern hier ein eigenes Template System genutzt wird hatte ich die Hoffnung, dass mir jemand mit seinem Wissen helfen kann. Ich brauche eine Art FrontendModul, dem ich im Quellcode eine Route verpassen kann.
Was ich nicht möchte ist diese Route im Backend einfügen. Da weiß ich wie ich vorgehen müsste.
Im PageController gab es ein Beispiel, welches vielversprechend aussah, da bin ich aber nicht weiter gekommen:
PHP-Code:
// src/Controller/Page/ExamplePageController.php
namespace App\Controller\Page;
use Contao\CoreBundle\ServiceAnnotation\Page;
use Contao\PageModel;
use Contao\PageRegular;
use Symfony\Component\HttpFoundation\Response;
/**
* @Page(contentComposition=true)
*/
class ExamplePageController
{
public function __invoke(PageModel $pageModel): Response
{
// The legacy framework relies on the global $objPage variable
global $objPage;
$objPage = $pageModel;
// Render the page using the PageRegular handler from the legacy framework
return (new PageRegular())->getResponse($pageModel, true);
}
}
Lesezeichen