Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ciwan 39 posts 69 karma points
    Jun 12, 2017 @ 07:33
    Ciwan
    0

    Umbraco Fields outside of Surface Controller?

    Hello everyone

    I am fairly new to Umbraco so some of the things I say might seem very basic to you.

    I have an Umbraco Surface Controller (MemberSurfaceController.cs). I like having my controllers light, so I want them simply calling "services" that deal with the logic and processes that need to happen. The service used by my Surface Controller is (LslMemberService.cs). Here's what that looks like:

    namespace LSLUmbraco.Services.Implementations
    {
      // various using statements
    
      public class LslMemberService : ILslMemberService
      {
        private readonly ICustomerService _customerService;
        private readonly ISystemService _systemStatusService;
        private readonly IMemberService _memberService;
        private readonly IEmailService _emailService;
        private readonly MembershipHelper _membershipHelper;
    
        public LslMemberService(ISystemService systemStatusService, ICustomerService customerService, IEmailService emailService)
        {
          _systemStatusService = systemStatusService;
          _customerService = customerService;
          _emailService = emailService;
          _memberService = ApplicationContext.Current.Services.MemberService;
          _membershipHelper = new MembershipHelper(UmbracoContext.Current);
        }
    
        // other code omitted
    
        private string BuildEmailBody(string emailAddress, string verificationToken)
        {
          var emailBody = // need to grab email template from field in Umbraco
          return emailBody;
        }
      }
    }
    

    Not sure if you noticed, but in my method BuildEmailBody(params) I would like to grab the email template from Umbraco.

    I'm not sure what the technical Umbraco term is, but I call them Umbraco Fields. I have an Umbraco field of type rich text editor where the Admin of the site can set his/her email template.

    email template field

    My question is, how do I grab that Umbraco field from my LslMemberService?

    Any help would be greatly appreciated.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 12, 2017 @ 07:35
    Dave Woestenborghs
    0

    Hi Ciwan,

    A few questions ?

    What is the document type alias of the "register page" ?

    Are you using modelsbuilder ?

    Dave

  • Ciwan 39 posts 69 karma points
    Jun 12, 2017 @ 07:40
    Ciwan
    0

    Hi Dave

    Do you mean this?

    enter image description here

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 12, 2017 @ 07:49
    Dave Woestenborghs
    0

    Hi Ciwan,

    This is exactly what i meant.

    So in your service you can do this :

    var registrationPage = UmbracoContext.Current.ContentCache.GetSingleByXPath("//Registration[@isDoc]");
    

    This assumes you have only one page of this type in your website.

    Once you have that you can do this to get the field with the mail body :

    var mailbody = registrationPage.GetPropertyValue<IHtmlString>("aliasofmailbodyfield");
    

    That will give you the mail body field

    Dave

  • Ciwan 39 posts 69 karma points
    Jun 12, 2017 @ 08:11
    Ciwan
    0

    Thanks Dave, I tried as suggested, but it seems like that first line isn't finding it! The registrationPage is null.

    enter image description here

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 12, 2017 @ 08:39
    Dave Woestenborghs
    0

    Hi Ciwan,

    Can you try this

    UmbracoContext.Current.ContentCache.GetSingleByXPath("//registration[@isDoc]");

    Maybe I made a error in the casing.

    Dave

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 14, 2017 @ 09:01
    Dave Woestenborghs
    0

    Hi Ciwan,

    Did my last comment work for you ?

    Dave

  • Ciwan 39 posts 69 karma points
    Jun 14, 2017 @ 09:16
    Ciwan
    0

    Thanks Dave, I believe it did. :)

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 14, 2017 @ 09:20
    Dave Woestenborghs
    0

    Nice to hear that.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft