I am getting the error:
An exception has been thrown during the rendering of a template ("The menu "main" is not defined.") in src\Acme\BasicCmsBundle\Resources\views\Default\pa ge.html.twig at line 4.
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception:
InvalidArgumentException »
I am on the page about menu
http://symfony.com/doc/master/cmf/tutorial/the-frontend.html
Where is the mistake?
Expand|Select|Wrap|Line Numbers
- <?php
- // src/Acme/BasicCmsBundle/DataFixtures/PHPCR/LoadPageData.php
- namespace Acme\BasicCmsBundle\DataFixtures\PHPCR;
- use Acme\BasicCmsBundle\Document\Page;
- use Doctrine\Common\DataFixtures\FixtureInterface;
- use Doctrine\Common\Persistence\ObjectManager;
- use Doctrine\ODM\PHPCR\DocumentManager;
- class LoadPageData implements FixtureInterface
- {
- public function load(ObjectManager $dm)
- {
- if (!$dm instanceof DocumentManager) {
- $class = get_class($dm);
- throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
- }
- $parent = $dm->find(null, '/cms/pages');
- $rootPage = new Page();
- $rootPage->setTitle('main');
- $rootPage->setParentDocument($parent);
- $dm->persist($rootPage);
- $page = new Page();
- $page->setTitle('Home');
- //$page->setParentDocument($parent);
- $page->setParentDocument($rootPage);
- $page->setContent(<<<HERE
- Welcome to the homepage of this really basic CMS.
- HERE
- );
- $dm->persist($page);
- $page = new Page();
- $page->setTitle('About');
- $page->setParentDocument($rootPage);
- $page->setContent(<<<HERE
- This page explains what its all about.
- HERE
- );
- $dm->persist($page);
- $dm->flush();
- }
- }
Expand|Select|Wrap|Line Numbers
- {# src/Acme/BasicCmsBundle/Resources/views/Default/page.html.twig #}
- <h1>{{ page.title }}</h1>
- {{ knp_menu_render('main') }}
- <p>{{ page.content|raw }}</p>
- <h2>Our Blog Posts</h2>
- <ul>
- {% for post in posts %}
- <li><a href="{{ path(post) }}">{{ post.title }}</a></li>
- {% endfor %}
- </ul>