ConsoleLog helper, IsSectionDefined method - This week in Orchard (03/01/2020)

Gábor Domonkos's avatar
Localization, Documentation, This week in Orchard, Shape

Happy new year everyone! There was no meeting this week, but in the first post of 2020, we would like to give you a nice overview of the latest improvements of Orchard Core, including the ConsoleLog helper, updated documentation, the new look and feel of our weekly blog post and newsletter and many more!

Orchard Core updates

ConsoleLog Razor helper and Liquid filter

Sometimes you may struggle to get the correct placement or the available alternates of a shape. From now there is a shape dumper to try and see what was going on. Dean Marcussen adapted the dumper to use the ConsoleLog, so when you dump ZoneHolding, you see the holding zone, then another log with all the items in it, with their alternates (as they are calculated at execution time). Let's say you rewrite the Content-BlogPost.liquid to Content-BlogPost.cshtml. In this case, you can use the ConsoleLog Razor helper in the following way:


Then hit F12 if you are using Google Chrome and check the content of the console.

The ConsoleLog extension method can be used to dump data from well-known properties, or objects serializable to JSON to the browser console. But if you prefer Liquid instead of Razor, you can use the console_log Liquid filter that will do the same for you in Liquid! Check out the documentation for more info about these new features! Thanks to this new shape dump feature you can construct your Orchard Core site faster and easier!

Register User class as an accessible Liquid member

Let's say you want to get the User fields from a Liquid template when you are using the UserCreated event of a Workflow. To do that, it's required to make this class an available one from Liquid. Else the only value accessible is the Workflow.Input.User which returns the username. If you check the content of the UserLiquidTemplateEventHandler class, you will see that the User class has been registered.

Handle error while rendering resources

When using the ResourcesTagHelper and referencing a non-existing resource, it breaks page rendering with the following error:

Error 500 : InvalidOperationException: Could not find a resource of type 'X' named 'Y' with version 'Z'.

It should log an error, but not break the rendering. To do not break the rendering, the Process method of the ResourcesTagHelper now catches the exception if any and creates a log entry instead of breaking the rendering.

Clarify getting started and update for .NET Core 3 in the documentation

The Getting Started page of the documentation is one of the most important parts of the Orchard Core documentation where you can see how you can add the Orchard Core NuGet packages to your .NET Core web application. Now this page got some more details about how to create your empty .NET Core web application, how to use the dev packages of Orchard Core and so on.

Cloning removed LocalizationSet

When cloning a content item that has a LocalizationSet, a duplicate entry of a language was created. That's because the LocalizationSet was not being cleared when cloning so a duplicate entry would be created for a locale. The fix was to remove the LocalizationSet when cloning in the CloningAsync method of the LocalizationPartHandler. Here you can see that the LocalizationSet of the cloned part will get an empty string value.

Added IsSectionDefined method

Let's say you are using RenderSection to render a zone in a view and you want to render certain HTML elements before and after rendering the zone, only if the zone is available.

First, you can call IsSectionDefined to verify if the zone is present as follows:

@if (IsSectionDefined("News"))
<div class="news">
@await RenderSectionAsync("News", required: false)

But it was throwing the following exception.

InvalidOperationException: IsSectionDefined invocation in '/Areas/XXX/Views/XXX.cshtml' is invalid. IsSectionDefined can only be called from a layout page.

The fix for this issue was to add the IsSectionDefined method to the RazorPage abstract class.

News from the community

Improving our This week in Orchard newsletter

We published our first This week in Orchard post on the 20th of June, 2018 and since then we wrote 75 posts, 76 with this one :). Our goal is with the series is to give you valuable news and demos about the happenings around Orchard and Orchard Core every week. To do it we improve the posts from time to time and from this year we would like to introduce a new pack of changesets.

Last month we created a poll on Twitter and asked you: would you like keywords about highlights in the title of This week in Orchard blog posts and newsletter subjects? We had 10 votes and everyone agreed that this would help to search, so from now, we changed the title in this way. And that's not everything about the title. Regarding the current date, we used the following format: mm/dd/yyyy. From this year we will use the following format: dd/mm/yyyy, which is a more international way to represent the date.

We also changed the structure of the posts a little bit. Let's see the old way:

  • On Orchard 1.x: contained everything that is related to Orchard 1.x.
  • On Orchard Core: contained everything that is related to Orchard Core like the new features, bug fixes, new websites built with Orchard Core.
  • Demos: this section was inside the On Orchard Core section and contained demos about Orchard Core. If there were demos about Orchard 1.x, the On Orchard 1.x also had this section.
  • On Lombiq: news from Lombiq.

And now let's see the structure that we use from this year:

  • On Orchard 1.x: new features and news around Orchard 1.x, but the demos will be in a separate place together with Orchard Core demos.
  • Orchard Core updates: bug fixes, new features of Orchard Core.
  • Demos: here come the demos of Orchard 1.x and Orchard Core.
  • News from the community: new websites, news about the Harvest, blog posts about Orchard Core, news from Lombiq, everything that is not related to the code itself.

And if you are subscribed to our newsletter you will see that we created a new template for our emails that looks nicer and easier to read. We hope you will like our improvements!

Feel free to contact us and share your thoughts about the current improvements or add your own ideas that could help us to make This week in Orchard better!

Orchard Dojo Newsletter

Now we have 112 subscribers of the Lombiq's Orchard Dojo Newsletter! 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 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!

No Comments

Add a Comment