Skip to content

Instantly share code, notes, and snippets.

@FabianSchmick
Created July 19, 2019 11:24
Show Gist options
  • Save FabianSchmick/b7c58bfb33bed4fd9e9d326fe5205ecd to your computer and use it in GitHub Desktop.
Save FabianSchmick/b7c58bfb33bed4fd9e9d326fe5205ecd to your computer and use it in GitHub Desktop.
Symfony receive content for ajax or normal request
{% block html %}
<!DOCTYPE html>
<html lang="de">
<head>
</head>
<body>
{% block body %}{% endblock %}
</body>
</html>
{% endblock html %}
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends Controller
{
/**
* @Route("/", name="default")
*/
public function indexAction(Request $request)
{
return $this->render('index.html.twig');
}
}
{% extends 'base.html.twig' %}
{% block html %}
{% if app.request.isXmlHttpRequest or embed is defined %}
{{ block('body') }}
{% else %}
{{ parent() }}
{% endif %}
{% endblock html %}
{% block body %}
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment