diff --git a/src/Controller/IframeController.php b/src/Controller/IframeController.php index 6245772..98dc69a 100644 --- a/src/Controller/IframeController.php +++ b/src/Controller/IframeController.php @@ -16,6 +16,7 @@ use IQ2i\StoriaBundle\View\ViewBuilder; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Profiler\Profiler; use Twig\Environment; @@ -33,8 +34,20 @@ public function __invoke(Request $request, ?Profiler $profiler): Response $profiler->disable(); } + $view = $this->viewBuilder->createFromRequest($request); + if (null === $view) { + throw new NotFoundHttpException(); + } + + $content = $view->getCurrentVariant()->getHtmlContent(); + + $pos = strripos((string) $content, ''); + if (false !== $pos) { + return new Response($content); + } + return new Response($this->twig->render('@IQ2iStoria/iframe.html.twig', [ - 'view' => $this->viewBuilder->createFromRequest($request), + 'content' => $content, ])); } } diff --git a/templates/iframe.html.twig b/templates/iframe.html.twig index 59d2527..50af597 100644 --- a/templates/iframe.html.twig +++ b/templates/iframe.html.twig @@ -1,19 +1,19 @@ -{# @var view \IQ2i\StoriaBundle\View\Dto\View #} - UI Storia + + + + {% block stylesheets %}{% endblock %} {% block javascripts %}{% endblock %} - {% block body %} - {{ view.currentVariant.htmlContent|raw }} - {% endblock %} + {% block body %}{{ content|raw }}{% endblock %} \ No newline at end of file diff --git a/tests/TestApplication/config/routes.php b/tests/TestApplication/config/routes.php index cdf20d8..8d0e600 100644 --- a/tests/TestApplication/config/routes.php +++ b/tests/TestApplication/config/routes.php @@ -15,7 +15,10 @@ use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; return function (RoutingConfigurator $routes) { - $routes->add('home', '/')->controller(TemplateController::class)->defaults(['template' => 'home.html.twig']); + $routes->add('home', '/') + ->controller(TemplateController::class) + ->defaults(['template' => 'pages/homepage.html.twig']); + $routes->import('@IQ2iStoriaBundle/config/routes.php')->prefix('/storia'); if ('dev' === $routes->env()) { diff --git a/tests/TestApplication/storia/pages/homepage/homepage.html.twig b/tests/TestApplication/storia/pages/homepage/homepage.html.twig index d7b5a93..4825691 100644 --- a/tests/TestApplication/storia/pages/homepage/homepage.html.twig +++ b/tests/TestApplication/storia/pages/homepage/homepage.html.twig @@ -1 +1,11 @@ -This is a homepage template \ No newline at end of file +{% extends 'base.html.twig' %} + +{% block body %} + {% block hero %} +

This is the homepage hero

+ {% endblock %} + + {% block content %} +

This is the main content of the page

+ {% endblock %} +{% endblock %} \ No newline at end of file diff --git a/tests/TestApplication/templates/homepage.html.twig b/tests/TestApplication/templates/base.html.twig similarity index 50% rename from tests/TestApplication/templates/homepage.html.twig rename to tests/TestApplication/templates/base.html.twig index 9d037ef..1b3889f 100644 --- a/tests/TestApplication/templates/homepage.html.twig +++ b/tests/TestApplication/templates/base.html.twig @@ -3,8 +3,13 @@ + - Hello world! + {% block body %}{% endblock %} + + {% block footer %} +

This is a footer

+ {% endblock %} \ No newline at end of file diff --git a/tests/TestApplication/templates/pages/homepage.html.twig b/tests/TestApplication/templates/pages/homepage.html.twig new file mode 100644 index 0000000..99a7b93 --- /dev/null +++ b/tests/TestApplication/templates/pages/homepage.html.twig @@ -0,0 +1,11 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {% block hero %} +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla viverra dignissim mi, eget egestas mi tincidunt vitae. Nunc nulla neque, sodales at rhoncus eget, pulvinar quis orci. Nulla facilisi.

+ {% endblock %} + + {% block content %} +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla viverra dignissim mi, eget egestas mi tincidunt vitae. Nunc nulla neque, sodales at rhoncus eget, pulvinar quis orci. Nulla facilisi. Nam vel orci nec augue scelerisque lacinia. Phasellus pellentesque leo nulla. Ut neque urna, ultricies eu tincidunt at, mollis sagittis dui. Suspendisse ac diam sed lectus mollis dapibus. Donec dui ipsum, scelerisque at rutrum ac, molestie sed ex. Praesent congue laoreet justo at porttitor. Vestibulum non rutrum tortor, ut laoreet libero. Vivamus ut neque at odio finibus venenatis.

+ {% endblock %} +{% endblock %} \ No newline at end of file