This week in Orchard - 09/06/2019

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

Lots of PRs merged to Orchard Core this week that adds new improvements, fixes, and features. You could also read a demo about the Content Fields Indexing, that is a very useful feature for the developers: they can now query content items based on the value of the fields! Oh, and we will have a meetup soon in Budapest, where Lombiq will giving a talk on Orchard. Get ready for a longer post about these amazing features! We promise: you won't regret reading it!

On Orchard Core

Add ORCHARD_APP_DATA Environment Variable section

If you want to change where the App_Data folder is, you can define an environment variable called ORCHARD_APP_DATA. Paths can be relative to the application path (./App_Data), absolute (/path/from/root), or fully qualified (D:\Path\To\App_Data). If the folder does not exist the application will attempt to create it.

Localization files publishing

When we deploy the app it will also publish the Localization folder, which is where the localization files go. Instead of the App_Data/Localization, they go into the Localization folder of the content root.

Content Culture Picker improvements

There is a new Liquid helper called switch_culture_url, that is responsible to return the URL of the Action that switches cultures. The ContentCulturePickerContainer is the template of the culture picker, that you can add in your front end themes to display a customized drop-down or a list of options to change the culture of the website. There was no example about how to override this using Liquid, now the documentation has an example using the new switch_culture_url helper.

Workflows Internationalization

Now every Task and Event have a LocalizedString property called DisplayText. With this change, you can localize the title of every activity.

Make setting the page title format accessible to site administrators

When you navigate to the general settings page you can find a new option called Page title format. Here you can now provide a Liquid expression to customize the way how you would like to render the title of your page.

In the screen, you can see that we set the Page title format to {% page_title Site.SiteName, position: "before", separator: " -.-.-.- " %}

By providing before as the position, we will show the name of the site first, then the title of the page with a custom separator. Check the second tab in the screenshot above to see the result of the expression.

Handle UnauthorizedResult

When trying to access an unauthorized ContentItem in the front end, the ItemController returns an UnauthorizedResult. Until there, it's correct. However, UnauthorizedResult is treated like any other error and an error message is returned: "An error occurred while executing this request." leaving us thinking there is a bug.

The solution is we need to return the Forbid or Challange results, not just Unauthorized. If you are authenticated, we can just return Forbid to say you don't have access to this page. If you are not authenticated, we return a challenge, that will be redirecting you to the login page to give you a chance to authenticate yourself.

In the future in most of the controllers, we should use this logic.

Add documentation to health check

The HealthChecks module is just enabling the middleware and the new documentation now mentions that the default endpoint is 'health/live'.

Add support for typed shape tag helper properties

There is a shape tag helper with the following syntax:

<shape type="Foo" />

This will render the shape typed Foo. The Razor syntax to do the same is:

@await DisplayAsync(await New.Foo());

You can pass parameters inside your page:

@await DisplayAsync(await New.Foo(Age: 18, Color: "Green"));

You can do the same using the shape tag helper:

<shape type="Foo" age="18" color="Green" />

Let's say you create a file Foo.cshtm, that is the default template for the Foo shape. Inside that you can do the following: @Model.Age. What happens here is that you don't have IntelliSense for Age, because it's not typed.

When you write the following in your template, what you get for the @age is the string 18.

var age = 18;

<shape type="Foo" age="@age" color="Green" />

In Razor, if the property doesn't exist on the type (which is the case here, because it's dynamic) it will be assigned as a string. It will evaluate that doing a .ToHtmlString(). If you really want to get integers, you have a new option in Razor tag helpers to bind a custom property with a prefix.

<shape type="Foo" prop-age="@age" prop-color="Green" />

Using the prop- prefix the value will be converted to a property on the shape with the type of the variable that is passed. The @age will be the variable itself, in this case, it will keep the type of that we passed here directly to the property age, which is assigned to the shape. So the shape will keep the properties with the variable type instead of converting them to IHtmlContent. With this new improvement, you can pass complex objects to your shape types. For example, you can pass your object directly to a shape without needing a ViewModel.


Content fields indexing

Now we have a new module which is Content Fields Indexing (SQL), that adds database indexing for content fields. You can also find documentation about the available tables for the database indexing and the usage of these index tables from a class, from a Razor template and from Liquid too.

First, enable the Content Fields Indexing (SQL) module from the admin. If you are using the Blog recipe, you will have a Blog Post content type, thas has a Subtitle Text Field. Let's create some new Blog Posts. Let's create two published and one draft posts. Now head to the database, where you will see the new tables, like DateFieldIndex, BooleanFieldIndex, TextFieldIndex, etc. Because the Subtitle is a Text Field, let's check the content of that table.

You can see the three blog posts here, where you can also notice that one of them hasn't published yet. If you enable the SQL Queries module, you can add a new SQL query to list the Blog Posts from the TextFieldIndex table.

Hit Save and then Run the query. At the bottom of the screen, you will get the result of the query: the three BlogPost content types. Do you know developers from your company who'd love this feature? Show them that now they can query content items based on the value of the content fields!

On Lombiq

Talentera.Net meetup

This one is for our friends in Budapest: we've partnered with the agile carrier building agency Talentera to bring you .Net meetups! The first one will be in three weeks, us giving a talk on Orchard. Join if you're in the city!

Orchard Dojo Newsletter

Now we have 91 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!

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