@using Umbraco.Cms.Core
@using Umbraco.Cms.Core.Serialization
@using Umbraco.Cms.Core.Services
@using Umbraco.Cms.Core.Models
@inject IContentService ContentService
@inject IJsonSerializer Serializer
@{
// Create a variable for the GUID of the page you want to update
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");
// Get the page using the GUID you've defined
var content = ContentService.GetById(guid); // ID of your page
// Get the media you want to assign to the footer links property
var media = Umbraco.Media("bca8d5fa-de0a-4f2b-9520-02118d8329a8");
// Create an Udi of the media
var mediaUdi = Udi.Create(Constants.UdiEntityType.Media, media.Key);
// Get the content you want to assign to the footer links property
var contentPage = Umbraco.Content("665d7368-e43e-4a83-b1d4-43853860dc45");
// Create an Udi of the Content
var contentPageUdi = Udi.Create(Constants.UdiEntityType.Document, contentPage.Key);
// Create a list with different link types
var externalLinks = new List<Link>
{
// External Link
new Link
{
Target = "_blank",
Name = "Our Umbraco",
Url = "https://our.umbraco.com/",
Type = LinkType.External
},
// Media
new Link
{
Target = "_self",
Name = media.Name,
Url = media.MediaUrl(),
Type = LinkType.Media,
Udi = mediaUdi
},
// Content
new Link
{
Target = "_self",
Name = contentPage.Name,
Url = contentPage.Url(),
Type = LinkType.Content,
Udi = contentPageUdi
}
};
// Serialize the list with links to JSON
var links = Serializer.Serialize(externalLinks);
// Set the value of the property with alias 'footerLinks'.
content.SetValue("footerLinks", links);
// Save the change
ContentService.Save(content);
}