0

I was trying to extend RenderField pipeline, I tried below, but still not getting single-line or multi-line Field TypeKey. I am using Sitecore 9.1 initial release is anything I am missing?

-Sitecore.Pipelines.RenderField.GetFieldValue
-Sitecore.Pipelines.RenderField.GetTextFieldValue
-Sitecore.Pipelines.RenderField.GetMemoFieldValue

Reference blog I followed

Using custom tokens in Sitecore

reference blog

1 Answer 1

1

I tried this approach to extend the functionality of the pipeline Sitecore.Pipelines.RenderField.GetTextFieldValue

  1. Extracted the code from the DLL and created my custom class like below.

TokenReplacer

namespace CMS.Feature.Replacer
{
    public class TokenReplacer
    {
        public void Process(RenderFieldArgs args)
        {
            Assert.ArgumentNotNull((object)args, nameof(args));
            this.EncodeFieldValue(args);
            string fieldTypeKey = args.FieldTypeKey;
            if (!fieldTypeKey.Equals("text", StringComparison.InvariantCulture) && !fieldTypeKey.Equals("single-line text", StringComparison.InvariantCulture))
                return;
            args.WebEditParameters.Add("prevent-line-break", "true");
        }

        protected virtual void EncodeFieldValue(RenderFieldArgs args)
        {
            Assert.ArgumentNotNull((object)args, nameof(args));
            if (!Settings.Rendering.HtmlEncodedFieldTypes.Contains(args.FieldTypeKey))
                return;
            args.Result.FirstPart = HttpUtility.HtmlEncode(args.Result.FirstPart);
        }
    }
}
  1. Created a patch file and put it into the below location.

wwwroot<solution-root-directory>\App_Config\Include\zzz\TokenReplacer.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:x="http://www.sitecore.net/xmlconfig/">
  <sitecore>   
    <pipelines>
      <renderField>        
        <processor x:after="*[@type='Sitecore.Pipelines.RenderField.GetTextFieldValue, Sitecore.Kernel']" type="CMS.Feature.Replacer.TokenReplacer, CMS.Feature.Replacer" />
      </renderField>
    </pipelines>
  </sitecore>
</configuration>

And I was able to get the single-line-text field type in my code.

enter image description here

And also the token like below.

enter image description here

Try this and update if you find any issue.

4
  • Hi @Sumit, thanks for the quick answer. I tried again as you suggest, for me all rendering component rich text field comes up but not the single-line and multiline field.
    – Singh
    Commented Mar 23, 2023 at 17:28
  • @Singh Did you extend the same Sitecore.Pipelines.RenderField.GetTextFieldValue pipeline? Commented Mar 24, 2023 at 7:49
  • Yes @Sumit,But not working
    – Singh
    Commented Mar 27, 2023 at 12:34
  • @Singh I don't know what is missing with your code, But I have checked it with OOTB one and it worked for me. And I also attached the screenshots. Commented Mar 27, 2023 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.