Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChrisMcKee/4961877 to your computer and use it in GitHub Desktop.
Save ChrisMcKee/4961877 to your computer and use it in GitHub Desktop.
Get Email Template By Template Name from Umbraco via /Base and content service Setting content service so that its available within the application from ANYWHERE that can access the application. Simple Example (So you'd need to clean your own shit up in the Rest Controller) The URL would be http://www.xxxx.local.dev/base/EmailTemplateHelpers/Get…

Using Umbraco Content Service outside of Umbraco context/control

Or Getting content from umbraco using the Umbraco Content Service

We could call it a guide to why Umbraco dont understand the term Gateway... but that would be harsh.

Get Email Template By Template Name from Umbraco via /Base and content service Setting content service so that its available within the application from ANYWHERE that can access the application.

Simple Example (So you'd need to clean your own shit up in the Rest Controller)

The URL would be

http://www.xxxx.local.dev/base/EmailTemplateHelpers/GetEmailTemplate/Email%20Standards

Chris McKee

namespace XXX.UI
{
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using Umbraco.Core;
using Umbraco.Core.Services;
public class UmbracoApplication : IApplicationEventHandler
{
public static IContentService UmbContentService { get; private set; }
//Normal crap the interface throws out here
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
UmbContentService = ApplicationContext.Current.Services.ContentService;
}
}
namespace XXX.UI.App.UmbracoBase
{
using System.Linq;
using Umbraco.Core.Services;
[Umbraco.Web.BaseRest.RestExtension("EmailTemplateHelpers")]
public class UmbracoEmailTemplateHelper
{
private static readonly IContentService ContentService = UmbracoApplication.UmbContentService;
[Umbraco.Web.BaseRest.RestExtensionMethod]
public static string GetEmailTemplate(string templateName)
{
var template = ContentService.GetChildrenByName(ContentService.GetChildrenByName(-1, "Email Templates")
.First()
.Id, templateName).First();
if (template == null || template.Properties.Count < 1 || template.Properties["template"] == null)
return string.Empty;
return template.Properties["template"].Value.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment