Produktiv Aufruf des Bootstrap Footers:

Symfony Beispiel

  • Import CSS Datei per Webpack/Encore (SASS)
    Der app.css.sass folgendes hinzufügen:
    							
    @import url("https://www.lifp.de/assets/collapsible-footer/styles/footer_bootstrap.css")
    							
    						
  • Aufruf in der .twig File:
    Hiermit wird der Footer gerendert, der 'path' verweist auf eine Funktion in einem Controller, siehe nächsten Schritt.
    							
    {{ render(path('core_microsite_footer')) }}
    							
    						
  • Funktion zum Holen des Footers
    							
    
    use Psr\Log\LoggerInterface;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use Symfony\Component\HttpClient\CachingHttpClient;
    use Symfony\Component\HttpClient\HttpClient;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\HttpKernel\HttpCache\Store;
    use Symfony\Component\Routing\Annotation\Route;
    use Symfony\Component\Security\Core\Security;
    use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
    
    
    class CoreController extends AbstractController
    {
        private LoggerInterface $logger;
        private Security $security;
        private CachingHttpClient $client;
    
        /**
         * CoreController constructor.
         * @param LoggerInterface $logger
         * @param Security $security
         */
        public function __construct(LoggerInterface $logger, Security $security)
        {
            $this->logger = $logger;
            $this->security = $security;
            $this->client = new CachingHttpClient(HttpClient::create(), new Store('var/cache/http'));
        }
    
    
        /**
         * @Route(
         *     "/{_locale}/microsite_footer",
         *     name="core_microsite_footer",
         *     locale="en",
         *      requirements={
         *         "_locale": "en|de"
         *     }
         * )
         * @param Request $request
         * @return Response
         */
        public function getFooterFromAssets(Request $request)
        {
            $content = null;
            try {
                $response = $this->client->request(
                    'GET',
                    'https://www.lifp.de/assets/collapsible-footer/index.php?framework=bootstrap&lang='.$request->getLocale()
                );
                $statusCode = $response->getStatusCode();
                if (200 == $statusCode) {
                    $content = $response->getContent();
                }
            } catch (ExceptionInterface $e) {
                //TODO ERROR log
            }
            return new Response($content, 200, ['content-type' => 'text/html']);
        }
    }