What is the best/simplest way to create an extra menu using the SimpleCmsBundle?

188 views
Skip to first unread message

Bruno Reis

unread,
Aug 8, 2014, 2:14:13 PM8/8/14
to symfony-...@googlegroups.com
Hi all, 

I've created a menu as shown in most (maybe all?) tutorials around: 

- Creating pages under the cms/simple node
- Using the {{ knp_menu_render('simple'... helper

But now I need a second menu for footer. The links are things like: "About Us", "Contact Us" and so on...

What is the best strategy to do it? 

I've created a node into the /cms/simple node called bottom menu and put these "childs" there.

But it has (of course) 2 "side effects":

The routes now have a "/bottom_menu/" in it.
The "Bottom Menu" item is appearing on my main menu. 

I've tried to create another node called /cms/bottom_menu. But when trying to create it's children, I saw it was not a page, but a "Generic" type of node. 

I'd like to have a solution similar to the SimpleCms one. With a page being the menu node and the content itself. 

Thanks in advance for any help on this. 

Oki Uimonen

unread,
Aug 9, 2014, 5:03:21 AM8/9/14
to symfony-...@googlegroups.com
Hi Bruno

Welcome to the group.

Correct me if I am wrong but I guess you cannot fully accomplish your goal with SimpleCmsBundle because a Page is the route and the menu node and the content all combined to one. You cannot thus have a routing that differs from the menu structure.

You can, however, branch both menus from the cms/simple root node, ie. cms/simple/main and cms/simple/misc and then render those menus like:

{{ knp_menu_render('simple/main') }} and {{ knp_menu_render('simple/misc') }}

You can use a RedirectRoute for the root nodes to redirect to the first Page in each menu.

This doesn't solve the URL issue, though. The addresses will still be like www.domain.tld/main/foobar.

Hope this helps somewhat
  Oki

Lukas Kahwe Smith

unread,
Aug 9, 2014, 5:17:43 AM8/9/14
to symfony-...@googlegroups.com

On 09 Aug 2014, at 11:03, Oki Uimonen <oki.u...@gmail.com> wrote:

> Hi Bruno
>
> Welcome to the group.
>
> Correct me if I am wrong but I guess you cannot fully accomplish your goal with SimpleCmsBundle because a Page is the route and the menu node and the content all combined to one. You cannot thus have a routing that differs from the menu structure.
>
> You can, however, branch both menus from the cms/simple root node, ie. cms/simple/main and cms/simple/misc and then render those menus like:
>
> {{ knp_menu_render('simple/main') }} and {{ knp_menu_render('simple/misc') }}
>
> You can use a RedirectRoute for the root nodes to redirect to the first Page in each menu.
>
> This doesn't solve the URL issue, though. The addresses will still be like www.domain.tld/main/foobar.
>
> Hope this helps somewhat

correct .. the issue is that the SimpleCmsBundle ony provides one dynamic router and therefore only one “root path”.
however you could look into configuring a second dynamic router pointing at a different root path .. the SimpleCmsBundle services should serve as a template for this.

regards,
Lukas Kahwe Smith
sm...@pooteeweet.org



signature.asc

Bruno Reis

unread,
Aug 9, 2014, 8:23:35 PM8/9/14
to symfony-...@googlegroups.com
Thanks Oki and Lucas, 

I think I've advanced a little, but still need your help, please. 

From SimpleCmf I got the initializers and could create the nodes. My tree got like this: 

ROOT:
  cms:
    routes:
    ...
    footer_menu:
      about_us:
      contact_us:
      privacy_policy:
      legal_disclaimer:

I also used the menu-phpcr.xml and the knp_menu_render seems to be identifying "footer_menu" as a menu. 

But I'm getting this error when calling knp_menu_render:

Can not determine the prefix. Either this is a new, unpersisted document or the listener that calls setPrefix is not set up correctly.

 
It seems that I missed something. I could not find the dynamic route configuration. If I run 

app/console config:dump cmf_simple_cms

I only get this: 

cmf_simple_cms:
    persistence:
        phpcr:
            enabled:              false
            basepath:             /cms/simple
            manager_registry:     doctrine_phpcr
            manager_name:         ~
            document_class:       Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page
            use_sonata_admin:     auto
            sonata_admin:
                sort:                 false
    use_menu:             auto

    # removed
    routing:              []

    # removed
    multilang:            []

but I see that the CmfSimpleCmsExtension has a prepend with some configs:

$prependConfig = array(
            'chain' => array(
                'routers_by_id' => array(
                    'router.default' => 0,
                    'cmf_routing.dynamic_router' => -100,
                )
            ),
            'dynamic' => array(
                'enabled' => true,
            )
        );
        if (isset($config['persistence']['phpcr']['basepath'])
            && '/cms/simple' != $config['persistence']['phpcr']['basepath']
        ) {
            $prependConfig['dynamic']['persistence']['phpcr']['route_basepaths'] = array($config['persistence']['phpcr']['basepath']);
        }
        $container->prependExtensionConfig('cmf_routing', $prependConfig);

Do I need to do something like that? Can I just change the config file? Would you have an example of a configuration with 2 dynamic routes set? 


David Buchmann

unread,
Aug 11, 2014, 3:00:31 AM8/11/14
to symfony-...@googlegroups.com
hi bruno,

> But now I need a second menu for footer. The links are things like:
> "About Us", "Contact Us" and so on...
>
> What is the best strategy to do it?

what you want to do define additional route roots:

http://symfony.com/doc/master/cmf/reference/configuration/routing.html#phpcr

for example /cms/simple/main and /cms/simple/bottom.

this will give you urls without the prefix. note that obviously there
can only be one content at the same url, so the order matters, and the
first root has precedence over the second (e.g. /cms/simple/test will
win over /cms/bottom/test when you call http://example.com/test)

on the simplecms bundle, the *basepath* needs to be the common root of
both, in my example /cms/simple (which is the default).

you can now add to both trees in the admin (you could also
/cms/whatever/something but that would not be used in routing)

for generating the menu, the name directly under basepath is what is
used as name of the menu. so knp_menu_render('main') and 'bottom' should
work as expected.

cheers,david

ps: just to confuse you (or maybe bring some deeper understanding) there
is an alternative option. simplecms unifies url, menu entry and content
organization in one single tree.
instead of doing the above things, you can also build a menu that just
references the content documents. you would configure the
cmf_menu.persistence.phpcr.content_basepath to /cms/simple to be able to
select from the simple cms content. (and not configure anything else
about route roots and such) then you create all your content directly
under /cms/simple. then you go to the menu admin and create the bottom
menu and link the menu-content to the content items you need. that way,
content can be in the main tree (and also occur in the main menu) and
additionally be in the footer.

David Buchmann

unread,
Aug 11, 2014, 3:01:09 AM8/11/14
to symfony-...@googlegroups.com
>> This doesn't solve the URL issue, though. The addresses will still be like www.domain.tld/main/foobar.
>>
>> Hope this helps somewhat
>
> correct .. the issue is that the SimpleCmsBundle ony provides one dynamic router and therefore only one “root path”.
> however you could look into configuring a second dynamic router pointing at a different root path .. the SimpleCmsBundle services should serve as a template for this.

this is no longer true. we fixed this with RoutingBundle 1.2 and
SimpleCmsBundle 1.1, you can now have as many route roots as needed.

see the other email i wrote for details...

cheers,david

Lukas Kahwe Smith

unread,
Aug 11, 2014, 3:02:58 AM8/11/14
to symfony-...@googlegroups.com
> see the other email i wrote for details…

ah right! .. great! :)
signature.asc

Bruno Reis

unread,
Aug 11, 2014, 4:45:57 PM8/11/14
to symfony-...@googlegroups.com
Thanks David. I still need some help, please. It seems that the routing started to consider new roots. But, match is not happening. We still need to do something else. 

If I print the NestedMatcher::matchRequest route collection, the routes ids are like these:

/cms/simple
/cms/simple/main
/cms/simple/footer_menu/about_us
/cms/simple/footer_menu

But, in the finalMatch, when the $compiledRoute is retrieved from the Page and getStaticPrefix() is called inside the UrlMatcher, the results are these:

/
/main
/footer_menu/about_us
/footer_menu

and the match is not happening. 

There are my configs:

cmf_core:
    persistence:
        phpcr:
            enabled: true

cmf_routing:
    dynamic:
        persistence:
            phpcr:
                route_basepaths:
                    - /cms/simple/main
                    - /cms/simple/footer_menu

and, in SimpleCmsBundle, of course, there is the basepath: 

->scalarNode('basepath')->defaultValue('/cms/simple')->end()

What is wrong? What do I need to change to make the match? I tried creating the pages in the loader and also on the admin, but the result was the same. 

Thank you for helping. 

* About the "confusion" part of your message... I think that having a similar structure for content and menu is better when possible. Specially to the final user. 
> --
> You received this message because you are subscribed to the Google Groups "symfony-cmf-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to symfony-cmf-us...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Bruno Reis

unread,
Aug 13, 2014, 6:07:17 AM8/13/14
to symfony-...@googlegroups.com
Anybody has a clue on this one? It seems so close...

Yoav Levy

unread,
Jan 29, 2015, 1:26:38 PM1/29/15
to symfony-...@googlegroups.com
@Bruno, Have you solved the problem?

Bruno Reis

unread,
Jan 29, 2015, 1:35:23 PM1/29/15
to symfony-...@googlegroups.com
Yep. The route_basepaths worked just fine: 

        persistence:
            phpcr:
                route_basepaths: 
                    - /site/homepage 
                    - /site/left_menu
                    - /site/footer_menu

Bruno Reis

unread,
Jan 29, 2015, 1:36:35 PM1/29/15
to symfony-...@googlegroups.com
Make sure to have a common basepath (/site) for all your site content. It will help you when exporting/importing the content as xml if needed. 

Yoav Levy

unread,
Jan 29, 2015, 1:53:12 PM1/29/15
to symfony-...@googlegroups.com
I keep geting 

No route found for "GET /"


localhost/home - o.k
localhost - No route found 

Bruno Reis

unread,
Jan 29, 2015, 2:10:39 PM1/29/15
to symfony-...@googlegroups.com
I do not remember how to generate a route for that. My app is not using / for specific reasons. I'm integrating it with an legacy app and the homepage is in the legacy app. Let's wait for the experts. I would just create a route for that, but I don't know if it's the right approach. 

--

David Buchmann

unread,
Jan 30, 2015, 7:22:44 AM1/30/15
to symfony-...@googlegroups.com
you need to create a route document as the root of one of those trees,
instead of the "normal" initializer. or if you redirect to something
anyways, just configure a standard symfony route to redirect.

On 29.01.2015 20:10, Bruno Reis wrote:
> I do not remember how to generate a route for that. My app is not using
> / for specific reasons. I'm integrating it with an legacy app and the
> homepage is in the legacy app. Let's wait for the experts. I would just
> create a route for that, but I don't know if it's the right approach.
>
> 2015-01-29 16:53 GMT-02:00 Yoav Levy <levy...@gmail.com
> <mailto:levy...@gmail.com>>:
>
> I keep geting
>
>
> No route found for "GET /"
>
>
> localhost/home - o.k
> localhost - No route found
>
> --
> You received this message because you are subscribed to the Google
> Groups "symfony-cmf-users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to symfony-cmf-us...@googlegroups.com
> <mailto:symfony-cmf-us...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "symfony-cmf-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to symfony-cmf-us...@googlegroups.com
> <mailto:symfony-cmf-us...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
Liip AG // Agile Web Development // T +41 43 500 39 80
CH-8005 Zurich // PGP 0xA581808B // www.liip.ch

Yoav Levy

unread,
Feb 1, 2015, 4:40:19 AM2/1/15
to symfony-...@googlegroups.com
I think cmf_core override cmf_routing_dynamic_persistence_phpcr_route_basepaths.

by modified the line 120 of CmfCoreExtention to  $routePaths = array($persistenceConfig['basepath'].'/routes/home'); my site root is up and runing.

app/console doctrine:phpcr:node:dump:

ROOT:
  cms:
    content:
      home:
        additionalInfoBlock:
          child1:
          child2:
      initiatives:
        additionalInfoBlock:
        political-environment:
    menu:
      main:
        initiatives:
          political-environment:
    routes:
      home:
        initiatives:
          political-environment:

Yoav
Reply all
Reply to author
Forward
0 new messages