GitHub Repo
🐙 GitHub
https://github.com/prjseal/Umbraco-13-Series/
📝 Guest Book
https://github.com/prjseal/Umbraco-13-Series/issues/1
Get Help
💬 Discord
🗣️ Facebook Group
https://www.facebook.com/groups/umbracowebdevs
🐘 Mastodon
https://umbracocommunity.social/
🗨️ Umbraco Forum
https://our.umbraco.com/forum/
☕Buy me a coffee
Code
MediaWithCropsExtensions.cs
namespace Freelancer.Extensions;
public static class MediaWithCropsExtensions
{
public static string GetAltText(this MediaWithCrops mediaItem, string altTextAlias = "altText")
{
var altText = mediaItem.Value<string>(altTextAlias);
return string.IsNullOrWhiteSpace(altText) ? string.Empty : altText;
}
}
PublishedContentExtensions.cs
namespace Freelancer.Extensions;
public static class PublishedContentExtensions
{
public static HomePage? GetHomePage(this IPublishedContent publishedContent)
{
return publishedContent.AncestorOrSelf<HomePage>();
}
public static SiteSettings? GetSiteSettings(this IPublishedContent publishedContent)
{
var homePage = GetHomePage(publishedContent);
return homePage?.FirstChild<SiteSettings>();
}
}
Freelancer.csproj
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet format --severity warn --verbosity diagnostic" />
</Target>
GlobalUsings.cs
global using Umbraco.Cms.Core.Models;
global using Umbraco.Cms.Core.Models.PublishedContent;
global using Umbraco.Cms.Web.Common.PublishedModels;
TestClass.cs
using Umbraco.Cms.Core.Services;
namespace Freelancer.Testing;
public class TestClass(IMediaService mediaService)
{
public void DoSomething()
{
var thing = mediaService.GetById(1);
}
}
ContentPage.cshtml
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.ContentPage>
@{
Layout = "Main.cshtml";
}
@await Html.GetBlockGridHtmlAsync(Model, "headerContent")
@await Html.GetBlockGridHtmlAsync(Model, "mainContent")
_ViewImports.cshtml
@using Freelancer.Extensions
@using Umbraco.Cms.Core.Services
@using Umbraco.Extensions
@using Umbraco.Cms.Web.Common.PublishedModels;
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
@using Umbraco.Cms.Web.Common.Views
@using Umbraco.Cms.Core.Models.Blocks
@using Umbraco.Cms.Core.Models.PublishedContent
@using Microsoft.AspNetCore.Html
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Smidge
@addTagHelper *, Our.Umbraco.TagHelpers
@inject Smidge.SmidgeHelper SmidgeHelper
@using Slimsy.Enums;
@addTagHelper *, Slimsy
@inject Slimsy.Services.SlimsyService SlimsyService
@using Slimsy.Extensions