Short codes, new content filters - This week in Orchard (22/05/2020)

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

Would you like to have an enhanced way to filter your content items in the content items list? Or are you looking for a feature that could work similarly to the short codes in WordPress? If your answers are yes, then this post is written for you!

Orchard Core updates

Configure Dev package source

If you would like to use the nightly builds of Orchard Core, then you will need to use MyGet instead of NuGet. Now the documentation contains a dedicated page to explain how to add the dev package source pointing to MyGet.

The documentation about how to Add Dev package source

Preserve external authentication tokens

There is a new feature to save the external tokens to be able to reuse them inside the user payload. They are encrypted inside the User object and the UserStore now implements the interface named IUserAuthenticationTokenStore. If you are about to manage tokens you just need to use the methods here to get/set/update or remove the tokens.

The GetTokenAsync and RemoveTokenAsync methods in UserStore

Document activate-links.js and extend functionality for nested menu items and action URLs

In the past, by using the activate-links.js script there was no way to expand a nested menu item if the active URL was in a sub-navigation item. Also if you had an active menu link like for example /todo-items, and navigated to an action from there like /todo-items/Create or /todo-items/Edit/{id} and the URL does not appear in the menu, no item was active in the menu.

Now the activate-links.js is extended to traverse URL segments to find out the active menu item and you can find a callback function to perform more actions on nested menus. There is also nice documentation about how to mark the active item in a menu.

Documentation about how to mark the active item in a menu

Short codes

Let us show you a way to inject some predefined HTML snippets like a media snippet that you can inject in your content editors. Today when we render for example an HTML BodyPart, we will optionally evaluate it as a Liquid template, and we will also use the new Short Codes feature of Orchard Core. The idea is that there is a module in Orchard Core called ShortCodes. This feature is about letting you evaluate some HTML blocks and replace short codes. We had that in Orchard 1 (remember the notion of filters and the tokens feature). This short code is actually looking much more like tokens in Orchard 1, but with a difference. You have a ShortCodeService that has a ProcessAsync method with string input. It processes and replaces all the short codes in the HTML and returns you another string.

The implementation of the ShortCodeService

The implementation is looking for IShortCode implementations, right now we have only one implementation, called MediaShortCode. When you call ProcessAsync, it will look for everything that has the text between [media] and [/media] and then take whatever is inside. Ensure its a valid URL and sanitize the output of this thing just in case it would contain some ref to a JavaScript or anything that could look like a script and returns the result.

The implementation of the MediaShortCode class

That is actually lighter than Liquid and easier to read. We use Liquid, because we had that, and of course you can still use Liquid. So, now you can create as many short codes as you want. For example there could be a Read more short code that is just about to render a Read more link from the summary to the full blog post.

Later we can have a service like ShortCodeDefinition, that would let you describe the short code that you can support with the name, the properties, and the description, like in Orchard 1, where whenever something is tokenizable there is a little pop-up button that you can use to list all the tokens that are available. This would be very useful to have in Orchard Core too. In Orchard 1, the tokens were code-based. There was a way to chain them, which means you could have a token to return the user and from the user you could say give me his email, and so on. But in this case you had to chain them in some way. For that you can use Liquid in Orchard Core by providing good flexibility to write anything without the limitation of tokens. The token is like in the middle between the short codes and Liquid. It's not powerful enough, but it's more powerful than short codes. Short codes would be super-easy to use and you can't chain them. But you can use them recursively like you could use maybe B short code to make something bold inside an A short code. They are individually functional, they don't work together like tokens would do. And we can make short codes dynamically or from the admin like templates. We could not change the behavior of tokens from the admin, but with this logic we could list all the available short codes and also add new custom short codes. Like you could add a new Twitter short code by yourself where the template itself could be in Liquid. In this case the users can use short codes that could be easier to write than Liquid. But why is it call short codes?

This name comes from WordPress, where you can already meet with a thing called shortcodes. Here is a screen from WordPress where you can see all the short codes. We can also add queries to this list, like let's inject the recent blog posts!

Shortcodes in WordPress

But that's enough talk for now, let's see the media short code in action! Imagine we have an Orchard Core site installed with the Blog recipe. Now navigate to the admin site and upload an image to the root of the Media Library. We added an image here called cat.jpg. Leave a comment below and try to guess what can you see in this picture!

Now navigate to the Blog and edit the built-in one. The goal is to add the media short code somewhere in the body of the post. Here you could see the way of using the media short code.

Using the Media short code in the body of a blog post

Now we have one step left to do: publish the post and see it in action! As we mentioned you can use as many short codes here as you want and can display multiple cats too!

The rendered blog post with the media short code

Demos

New content filters

The header section of the content items list will be updated and different modules and features can apply filters to the content listing. The first one is the culture filter, which means that you will have the availability to filter by localized content. You can also apply the taxonomy filter and filter by categories. Or you can filter by tags if you want.

To set up which taxonomies you want to use in the content list to filter on, you will find a new setting under Configuration -> Settings -> Taxonomy Contents List Filters, where you can choose which you want to use.

Set the taxonomies to filters in the contents list

If you are interested in the full demo and the way how it will implement, don't forget to check out the recording on YouTube!

News from the community

Poking around with Orchard Core

You can find a huge detailed blog post about how to build modular, multi-tenant applications using Orchard Core. Thanks to Lewis for this great post!

The beginning of the Poking around with Orchard Core post

A new website using Orchard Core

Shipwrecked alone on an uncharted island, explore, adapt, and navigate the land and perilous seas to stay alive. Brave the storm in Windbound, the new survival open-world role-playing game coming this August 2020 on PC, PlayStation 4, Xbox One, and Nintendo Switch. Let us show you the official website of Windbound - Brave the storm!

If you are interested in more websites using Orchard and Orchard Core, don't forget to visit Show Orchard. Show Orchard is a website for showing representative Orchard CMS (and now Orchard Core) websites all around the internet. It was started by Ryan Drew Burnett, but since he doesn't work with Orchard anymore, as announced earlier it is now maintained by our team at Lombiq Technologies.

The homepage of the Windbound game

Orchard Nuggets: How to call an external API from a workflow task?

In our newest Orchard Nuggets post we will show you the way how to use the Http Request Task to call an external API in Orchard Core! And guess what, we will also show you the way how you can work with the response data in your custom workflow task!

Orchard Nuggets post about calling external API from workflows

Check out the other posts for more such bite-sized Orchard tips and let us know if you'd have another question!

Orchard Core workshops

The contributors of Orchard Core will hold some unique online workshops in the coming months, between May and September 2020. So even with Orchard Harvest postponed due to the coronavirus pandemic we'll get some new learning events.

Lombiq's developers will also give two workshops, on using Orchard from the admin UI and on developing a module.

Are you looking to get up to speed with Orchard? Check out the workshops' details on the Orchard Core homepage!

Orchard Dojo Newsletter

Now we have 145 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