This seems to be an interesting issue, and I'm not sure if I'm missing something because it should be simple, but isn't.
Scenario
- I have one bundle named
AcmePageBundle
- Another bundle named
AcmeGalleryBundle
- I want to load an embedded view from the controller using the
AcmeGalleryBundle
bundle into a template file onAcmePageBundle
Code
AcmeGalleryBundle\Controller\DisplayController.php
class DisplayController extends Controller
{
public function embedAction($galleryId)
{
$gallery = $this->getDoctrine()->getRepository('AcmeGalleryBundle')->find($galleryId);
if (!$gallery) {
throw $this->createNotFoundException('Gallery could not be found');
}
return $this->render('AcmeGalleryBundle:Display:embed.html.twig', array(
'gallery' => $gallery,
));
}
}
AcmeGalleryBundle\Resources\views\Display\embed.html.twig
<div class="gallery">
{% for photo in gallery.photos %}
<a href="{{ photo.webPath }}" rel="shadowbox[gallery];">
<img src="{{ photo.webPath }}" height="100" width="100">
</a>
{% endfor %}
</div>
AcmePageBundle\Resources\views\Default\index.html.twig
{# ... extra HTML content #}
<h2>Gallery</h2>
{{ render(controller('AcmeGalleryBundle:Display:embed', {
'galleryId': 123
})) }}
{# rest of the HTML content #}
Errors
When trying to render the page that uses AcmePageBundle:Default:index.html.twig
, I get
An exception has been thrown during the rendering of a template ("Class 'AcmeGalleryBundle' does not exist") in AcmePageBundle:Default:index.html.twig at line 18.
but of course, AcmeGalleryBundle
does in fact exist. I'm suspecting a scope problem that I've missed somewhere.
Troubleshooting
- Ensured that
AcmeGalleryBundle
is loaded in theAppKernel.php
file - Tried adding
use Acme\GalleryBundle
to the top of theAcmePageBundle.php
bundle file. - Found an issue on GitHub relating to the problem with no response from the devs yet. I've added my own comments - this may in fact be a bug.
Am I missing anything obvious?