Re: Symfony CMF - Questions about menu rendering

18 views
Skip to first unread message

David Buchmann

unread,
Oct 24, 2014, 7:27:12 AM10/24/14
to Tamby Narivo, symfony-...@googlegroups.com
hi tamby,

well, this works but is really weird :-)
if you use the static content document from the ContentBundle instead,
you would not need to copy the menu per locale. the problem you get is
that the simple cms content does not expose routes pointing to it [1].
but as you have separate routes and a menu anyways, there is no reason
to use the SimpleCms Page document. if you use the content document and
have the menu point to that, and have the routes expose the proper
locale, things will "just work". if you need to add things to the footer
menu or change something, it will be a lot easier than with the
duplication you currently have.

cheers,david

[1] https://github.com/symfony-cmf/SimpleCmsBundle/issues/109

> Thanks for your answer David,
>
> Finally we've done something like this:
> - a locale is set for each route ("fr" is attached to
> "conditions-generales" and "en" to "terms-conditions")
> - a menu item is attached to a route; it means that we'll have as many
> versions of the menu item as the number of locales. So the structure of
> the CR will look something like this:
>
> ROOT:
> cms:
> content:
> simple:
> terms:
> contactus:
> menu:
> footer-menu:
> en:
> terms:
> contactus:
> fr:
> terms:
> contactus:
> routes:
> terms-conditions:
> conditions-generales:
> contact-us:
> nous-contacter:
>
> So when generating the menu for a given locale, it'll be something like
> this:
> {{ knp_menu_render('footer-menu/en', {'currentClass': 'active'}) }} if
> the current locale is "en"
> {{ knp_menu_render('footer-menu/fr', {'currentClass': 'active'}) }} if "fr"
>
> and the rendering is
> <ul>
> <li class="first"><a href="/terms-conditions">Terms &amp;
> Conditions</a></li>
> <li><a href="/contact-us">Contact us</a></li>
> </ul>
> in english and
>
> <ul>
> <li class="first"><a href="/conditions-generales">Conditions
> générales</a></li>
> <li><a href="/nous-contacter">Nous contacter</a></li>
> </ul>
> in french
>
> Instead of:
> <ul>
> <li class="first"><a href="/terms">Terms &amp; Conditions</a></li>
> <li><a href="/contactus">Contact us</a></li>
> </ul>
> previously because it was attached directly to the content document.
>
>
>
> Thanks again,
>
> On Fri, Oct 24, 2014 at 1:15 PM, David Buchmann <da...@liip.ch
> <mailto:da...@liip.ch>> wrote:
>
> hi tamby,
>
> please write to symfony-...@googlegroups.com
> <mailto:symfony-...@googlegroups.com> rather than to me
> personally. that way, everybody can see the question, help with replying
> and also find the discussion later when they have a similar problem.
>
> your content looks like you have a mix of simplecms and the more
> flexible separate menu and routes. if you want that your translated
> content also has translated urls, you need to put it into a content
> document that is referenced by the routes in all languages. this is
> because the url is the path in the repository. the menu items are just
> one document that is translated, they reference the content.
>
> when rendering the menu, the cmf dynamic router is asked to build the
> url for the content of the menu item. the router will look for a route
> in the current locale and fall back to the default locale if none exist.
> this means that you either need to configure the locale on each of your
> routes manually, or put add another path element for the locale, the
> routes then would look like:
>
> routes:
> en:
> terms-conditions:
> legal-mentions:
> fr:
> conditions-generales:
> mentions-legales:
>
> (we recommend the approach with having the locale in the url, as this
> will avoid name clashes. i guess "contact" would be the same word in
> french and english, for example)
>
> i hope that helps, otherwise please reply to the mailinglist, keeping
> the history of this discussion so people have the context.
>
> david
>
> On 24.10.2014 09:41, Tamby Narivo wrote:
> > Hi David,
> >
> > If you have the time, can you help me with this problem ?
> > I have a problem with the url generated on the menu items when using
> > "knp_menu_render".
> >
> > The structure of my CR is this:
> >
> > ROOT:
> > cms:
> > content:
> > simple:
> > terms:
> > legal:
> > menu:
> > footer-menu:
> > terms:
> > legal:
> > routes:
> > terms-conditions:
> > conditions-generales:
> > legal-mentions:
> > mentions-legales:
> >
> > When I do this to generate the menu on my template: {{
> > knp_menu_render('footer-menu', {'currentClass': 'active'}) }}, the
> > labels of the menu is OK: if the locale is "en", it displays
> "Terms and
> > Conditions" and if it's "fr", it displays "Conditions générales".
> >
> > My problem is, the url generated in the href is "/terms".
> > I guess knpmenu takes it from the path in the repository, but what I
> > want is that it displays "/terms-conditions" when it's in english or
> > "/conditions-generales" when it's in french.
> >
> > What should I do in your opinion so that I can get this behavior ?
> >
> > Thanks,
> >
> > Tamby
> >
> >
>
> --
> Liip AG // Agile Web Development // T +41 26 422 25 11
> <tel:%2B41%2026%20422%2025%2011>
> CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch <http://www.liip.ch>
>
>
>

--
Liip AG // Agile Web Development // T +41 26 422 25 11
CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch
Reply all
Reply to author
Forward
0 new messages