Using Content Picker Type for Macro Parameter in Umbraco

Umbraco 7.6 introduced the new property editor ContentPicker2 to replace ContentPicker. ContentPicker2 returns IPublishedContent instead of Node ID. When updating old content picker partial view macro parameters to the new content picker type, you will need to make some changes to your partial view

For example, if you have a parameter called Widget that currently uses the original content picker the following would return an integer node id.

Model.MacroParameters["widget"]

But a parameter using the new content picker would return an identifier in UDI format similar to the following.

umb://document/4fed18d8c5e34d5e88cfff3a5b457bf2

To convert the UDI string into an IPublishedContent object, it needs to be parsed and then passed into the Umbraco.TypedContent() method as follows.

var widget = Umbraco.TypedContent(Udi.Parse(Model.MacroParameters["widget"].ToString()));