In this tutorial, you will learn how to write some code that will access any multi-language data stored using Vorto within your route-hijacked controller. The focus of this tutorial is on complex data types, rather than getting data from a string or an int. It should be noted that this approach isn't the easiest or nicest approach. - for that I recommend you check out this article - if you have some requirement where you need to work with your multi-language content stored using Vorto, then manually getting the data yourself is probably your best option.

How Can I Use Vorto Within A Controller

When you create a property using Vorto on a document type and use Model Builder, it will get created as an Our.Umbraco.Vorto.Models.VortoValue. If you look at the class you'll see that it uses a collection of key-value pairs to store its data. This means that if you want to access the content you need to iterate through this collection, match the key (culture) to the pages current culture and then return the value:

Getting the data from a simple data type that has been wrapped with Vorto is simple. If you wrap a data type like related links property within Vorto, things get slightly more complex. For complex properties, Vorto serializes the properties and stores all the data as JSON. If you have a complex property that you want to get data from, you will need to use Json.NET and manually deserialize the data yourself. For related links, you can create a class that mirrors all the properties within the picker:

You still get the data out of Vorto the same, however, this time you use Json.Net on the property and deserialize it:

Getting an IPublished Content Out Of A Property

When you wrap slightly more complex properties with Vorto, like a nested content data-type, you can see the Umbraco UID being returned (more info about Umbraco UID here). In those situations, you can use this snippet:

You should now have the value the content editor added for that language and you are free to do any extra processing that you need. Happy Coding 🤘