.nethandlebars.jshandlebars.net

Handlebars.Net inserts Japanese Characters and converts them to Unicode Decimal Code


Simple example

        public class TemplateData {
             public string inputstring = "あ";
        }
        public static string HandleBar()
        {
            var message = "{{inputstring}}";
            var handlebars = Handlebars.Create();
            // needed so if statements work properly.
            handlebars.Configuration.UseNewtonsoftJson();
            var template = handlebars.Compile(message);
            var result = template(new TemplateData);

            return result;
        }

output will not be it is instead, あ

How do I fix this?


Solution

  • It seems Handlebars will escape some characters, so I added unescape code and it worked correctly.

    
            public class TemplateData {
                 public string inputstring = "あ";
            }
            public static string HandleBar()
            {
                var message = "{{inputstring}}";
                var handlebars = Handlebars.Create();
                // needed so if statements work properly.
                handlebars.Configuration.UseNewtonsoftJson();
                var template = handlebars.Compile(message);
                var result = template(new TemplateData);
    
                result = System.Net.WebUtility.HtmlDecode(result);
                return result;
            }