Exemple #1
0
 public void Process(HandlebarHelpersPipelineArgs pipelineArgs)
 {
     pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("ifEqual", (writer, options, context, args) =>
     {
         if (args[0] == args[1])
         {
             options.Template(writer, (object)context);
         }
         else
         {
             options.Inverse(writer, (object)context);
         }
     }));
 }
 public void Process(HandlebarHelpersPipelineArgs pipelineArgs)
 {
     pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("translate", (writer, context, args) =>
     {
         string input   = args[0].ToString();
         var translated = Sitecore.Globalization.Translate.Text(input);
         if (!string.IsNullOrEmpty(translated))
         {
             writer.Write(translated);
         }
         else
         {
             writer.Write("<!-- Nothing Found for Key: " + input + " -->");
         }
     }));
 }
        public void Process(HandlebarHelpersPipelineArgs pipelineArgs)
        {
            pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("LookupElement", (writer, context, args) =>
            {
                var input      = args[0];
                var lookupKey  = args[1].ToString();
                var lookupProp = args[2].ToString();


                System.Reflection.PropertyInfo info = input.GetType().GetProperties()[1];
                object dic = info.GetValue(input);



                writer.Write("testing");
            }));
        }
        public void Process(HandlebarHelpersPipelineArgs pipelineArgs)
        {
            pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("json", (writer, context, args) =>
            {
                object obj = args[0];

                //didn't like how Web Extensions Serializer looked for Expandos (Arrays of key values)
                //var jString = new JavaScriptSerializer().Serialize(obj);

                try
                {
                    var jString = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
                    writer.Write(jString);
                }
                catch (Exception ex)
                {
                    writer.Write(ex.ToString());
                }
            }));
        }
        static HandlebarManager()
        {
            //Run Pipeleine to get Helpers and Register them
            var args = new HandlebarHelpersPipelineArgs();

            Sitecore.Pipelines.CorePipeline.Run("handlebarHelpers", args);
            foreach (var helper in args.Helpers)
            {
                if (helper.Helper != null && !HandlebarsDotNet.Handlebars.Configuration.Helpers.ContainsKey(helper.Name) && !HandlebarsDotNet.Handlebars.Configuration.BlockHelpers.ContainsKey(helper.Name))
                {
                    HandlebarsDotNet.Handlebars.RegisterHelper(helper.Name, helper.Helper);
                }
                else
                {
                    if (helper.BlockHelper != null && !HandlebarsDotNet.Handlebars.Configuration.Helpers.ContainsKey(helper.Name) && !HandlebarsDotNet.Handlebars.Configuration.BlockHelpers.ContainsKey(helper.Name))
                    {
                        HandlebarsDotNet.Handlebars.RegisterHelper(helper.Name, helper.BlockHelper);
                    }
                }
            }
        }
Exemple #6
0
        public void Process(HandlebarHelpersPipelineArgs pipelineArgs)
        {
            pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("userSettings", (writer, context, args) =>
            {
                string key  = args[0].ToString();
                string area = UserSettingsConfiguration.DefaultArea;
                if (args.Length > 1 && !string.IsNullOrEmpty(args[1].ToString()))
                {
                    area = args[1].ToString();
                }

                var setting = SF.Foundation.Facets.Facades.UserSettings.Settings[key, area];
                if (!string.IsNullOrEmpty(setting))
                {
                    writer.Write(setting);
                }
                else
                {
                    //writer.Write("<!-- Nothing Found for Key: " + key + " -->");
                }
            }));
        }
        public void Process(HandlebarHelpersPipelineArgs pipelineArgs)
        {
            pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("placeholder", (writer, context, args) =>
            {
                var placeholderName = args[0].ToString();

                Guid currentRenderingId = RenderingContext.Current.Rendering.UniqueId;

                if (currentRenderingId != Guid.Empty)
                {
                    placeholderName = String.Format("{0}_{1}", placeholderName, currentRenderingId);
                }

                if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
                {
                    writer.Write(@"<div data-container-title=""{0}"">", placeholderName);
                }

                //save current context for later
                var oldContext       = HttpContext.Current.Items["HandlebarDataSource"];
                var oldRenderingItem = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item;

                Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item = Sitecore.Context.Item;

                //Updated to do new content rendering, similar to what the composite component does, as this was setting the context to the template.
                PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder", new RenderPlaceholderArgs(placeholderName, writer, new ContentRendering()));

                //put it back.
                HttpContext.Current.Items["HandlebarDataSource"] = oldContext;
                Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item = oldRenderingItem;

                if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
                {
                    writer.Write(@"</div>");
                }
            }));
        }
Exemple #8
0
        public void Process(HandlebarHelpersPipelineArgs pipelineArgs)
        {
            pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("formatDate", (writer, context, args) =>
            {
                string input    = args[0].ToString();
                DateTime parsed = DateTime.MinValue;
                if (DateTime.TryParse(input, out parsed))
                {
                    //We got a date, woo hoo!
                }
                else
                {
                    try
                    {
                        //Sitecore Date Vals are stored as Iso, could that be the issue?
                        parsed = Sitecore.DateUtil.IsoDateToDateTime(input);
                    }
                    catch
                    {
                        writer.Write("[Invalid Date]");
                    }
                }

                if (parsed != DateTime.MinValue)
                {
                    try
                    {
                        writer.Write(parsed.ToString(args[1].ToString()));
                    }
                    catch
                    {
                        writer.Write("[Invalid Format!]");
                    }
                }
            }));
        }