This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » eZ Publish 5 Platform » Call to ez_route when on a legacy...
expandshrink

Call to ez_route when on a legacy module view causes exception

Call to ez_route when on a legacy module view causes exception

Friday 19 September 2014 10:09:42 am - 5 replies

Hi all, we use ez_route for language switcher, but found a problem when the current view is not an actual location. I mean, if we browse i.e. to /content/search we get a symfony exception:

An exception has been thrown during the rendering of a template ("When generating an eZ Publish legacy fallback route, "uri" parameter must be provided."blunk.gif Emoticon

Perhaps we are doing anything in the wrong way?

Our conflicting call:

 {{ url( ez_route( params={"language": "esl-ES"} ) ) }}

Thanks for read!

Friday 19 September 2014 10:22:59 am

Hi Xavier

The exception is perfectly expected in your case... You directly call url() with an incomplete RouteReference (no route name or location object)... If you want to link a legacy route, please pass to ez_route() the same arguments you would pass to path() or url()

{{ url( ez_route( "ez_legacy", {"language": "esl-ES", "module_uri": "/content/search"} ) ) }}

Friday 19 September 2014 10:36:22 am

Many thanks for your quick reply Jérôme,

for sure this way will work, but what happens if I don't want/can hardcode the legacy route? I mean, in the code on my original post, you can see there is no specified any route, as in docs its explained that current route would be used in that case. And for content views it works perfectly, but not for legacy modules view.

Is there such a way to have automatically the current uri fetched? Cause at least I can have one twig for SF stack and another twig for the case a legacy module is called with "ez_legacy" add in the ez_route call.

In fact, my problem appeared not accessing /content/search but in /content/action after submitting an incomplete form, then I've checked /content/search to find that problem is a generic legacy module issue.

Many thanks!

Monday 22 September 2014 9:37:23 am

Hi Xavier

I suggest you do the following (I explained this tip at Summer camp 2014 for the migration process) :

  • Use 2 bundles : 
    • MyProject\SiteBundle, which will contain all your Symfony code (e.g. Twig templates, services not related to legacy)
    • MyProject\LegacyBundle, inheriting from MyProject\SiteBundle and will contain legacy related code

Advantage of doing so is that you'll be able to override all SiteBundles templates (and potentially other resources, see Symfony doc on bundle inheritance) in the LegacyBundle, making it possible to redefine variables for instance.

You will find an example on the repository of my MetalFrance website:

So, LegacyBundle inheriting from SiteBundle, the pagelayout will automatically be the one from LegacyBundle. It is inheriting the original one and adds logic to a few blocks and call the parent to display the original markup.

You can apply the same logic in your case. Say you have a menu block in your original layout (always declare blocks inside the pagelayout itself, not in subtemplates), where you place your language switcher. You could do something like this:

Hope this helps.

Monday 22 September 2014 10:17:48 am

will help me too... happy.gif Emoticon

Monday 22 September 2014 10:33:08 am

Great explanation Jérôme!

Many thanks!

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from