Fix Liquid QueryCollection access, renaming page route parameter - This week in Orchard (04/12/2021)

Gábor Domonkos's avatar
Query, Documentation, This week in Orchard, Liquid

Fixed Liquid QueryCollection access, an interesting bug when using the page route in Razor Pages, and updated libraries used in Orchard Core. Check out our current post to read about the details!

Orchard Core updates

Pager used the reserved "page" route parameter

The bug only happens if you are using Razor Pages at least one razor @page. In that case when you list the items of a given content type e.g. /Admin/Contents/ContentItems/Article?admin=674211458, the Pager links, in place of using our custom pattern /Admin/Contents/ContentItems/Article?admin=674211458&page=2, they use the default pattern where the content type is a query string parameter /Admin/OC.Contents/Admin/List?contentTypeId=Article&admin=...&page=2.

At this point, you can still go to a given Pager page. But then if you select a new filter option it removes the above query string contentTypeId parameter e.g. /Admin/Contents/ContentItems?q=status%3APublished. So in place of still listing the items of a specific content type, you go to the list of all content types in place of staying in the list of a specific type.

Removing the contentTypeId parameter is another issue filtering should preserve the existing parameters, but here we're only talking about the fact that the Pager links don't use the right custom pattern if at least a Razor @page is defined.

This is because the Pager uses a page route parameter to generate link URLs, but this is a reserved ASP .NET Core routing name. The solution is to remove this route value in the ActionLink shape before generating an URL and then explicitly add it as a query string parameter. Currently, as a workaround, there is a custom IShapeTableProvider.

So in one sentence, you are not allowed to use page in routes because it's a reserved word because of Razor Pages. And now it has been changed to pagenum everywhere.

Ranem Page to PageNum

Fixed Liquid QueryCollection access

Let's set up your site using the Agency recipe. That recipe contains a template for the Landing Page content type where we can test the Request.Query Liquid filter easily. If you check out line 19 of this template, you can see that we are using the Request.Query Liquid filter to say, give me the value of the test field from the query string.

Template for the Landing Page content type

But how can you use this one? The helper is just about to print the value of the query string by the given field. So, if we open up the predefined Landing Page content item and put something in the query string using the test, you will see the printed value on the page.

Using the test query string

It's an IQueryCollection whose underlying type is a QueryCollectionInternal, but we only allow access to QueryCollection. Jean-Thierry Kéchichian fixed it by creating a QueryCollection.

Fix Liquid QueryCollection access

Updated libraries

We have this Libraries page in the Orchard Core documentation that lists the different .NET libraries, the different Client-side libraries, and the different Tests libraries used in Orchard Core. In Orchard Core, the community always tries to use the latest versions of these libraries to make sure you will always get the latest bug fixes and the latest features provided by these libraries.

Orchard Core libraries

News from the community

Orchard Dojo Newsletter

Lombiq's Orchard Dojo Newsletter has 233 subscribers! We have started this newsletter to inform the community around Orchard with the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post is published to Orchard Dojo, including This week in Orchard of course.

Do you know of other Orchard enthusiasts who you think would like to read our weekly articles? Tell them to subscribe here!

If you are interested in more news around Orchard and the details of the topics above, don't forget to check out the recording of this week's Orchard meeting!

No Comments

Add a Comment