An exception has been thrown during the rendering of a template ("").
Bonjour,
J'essaye d'afficher un block Sonata mais j'ai l'erreur:
Code:
An exception has been thrown during the rendering of a template ("").
N'ayant pas plus d'informations, je ne sais pas du tout où peut se trouver l'erreur.
Mon code pour le Controller:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| public function showAction(UserProfileMenu $block)
{
$user = $this->getUser();
if (!is_object($user) || (!$user instanceof FOSUserInterface && !$user instanceof LDapUserInterface)) {
throw $this->createAccessDeniedException('This user does not have access to this section.');
}
return $this->render('bundles/ApplicationSonataUserBundle/Profile/show.html.twig', array(
'user' => $user,
'blocks' => $block,
));
} |
show.html.twig:
Code:
1 2 3 4 5 6
| <div class="span6 col-lg-12">
<h2>Bonjour <b>{{ app.user.firstname }}</b></h2>
<p>Vous êtes connecté avec le nom d'utilisateur <em>{{ app.user.username }}</em>.</p>
</div>
{{ sonata_block_render(blocks) }} |
Et enfin, le code de mon block si cela peut servir:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| <?php
namespace App\Block;
use App\Entity\BlogPost;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Mapper\FormMapper;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\Form\Validator\ErrorElement;
use Sonata\BlockBundle\Block\Service\BlockServiceInterface;
class UserProfileMenu extends AbstractBlockService implements BlockServiceInterface
{
/**
* @var EntityManagerInterface
*/
protected $entityManager;
public function __construct(
EntityManagerInterface $entityManager,
$name = null,
EngineInterface $templating = null
) {
$this->entityManager=$entityManager;
parent::__construct($name, $templating);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'url' => false,
'title' => 'Posts',
'template' => 'bundles/IntranetBundle/Block/block_user_last_posts.html.twig',
));
}
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
// merge settings
$settings = $blockContext->getSettings();
$posts = false;
$posts = $this->entityManager->getRepository(BlogPost::class)->findAll();
return $this->renderResponse($blockContext->getTemplate(), [
'posts' => $posts,
'block' => $blockContext->getBlock(),
'settings' => $settings
], $response);
}
} |
Quelqu'un a déjà eu cette erreur? Ou a des pistes? Je suis bloquée :/
Merci d'avance