Esempio n. 1
0
        // GET: Overview
        public ActionResult Index()
        {
            var model = new OverviewList()
            {
                ReadMore = Sitecore.Globalization.Translate.Text("Read More")
            };

            model.AddRange(RenderingContext.Current.ContextItem.GetChildren(Sitecore.Collections.ChildListOptions.SkipSorting)
                           .Select(i => new OverviewItem()
            {
                URL   = LinkManager.GetItemUrl(i),
                Title = new HtmlString(FieldRenderer.Render(i, "contentheading")),
                Image = new HtmlString(FieldRenderer.Render(i, "decorationbanner", "mw=500&mh=333"))
            }
                                   ));
            return(View(model));
        }
        public ActionResult React()
        {
            ViewBag.Module = "Cito.default.Header";//Would it be useful to transfer this information to the rendering?
            var item   = RenderingContext.Current.Rendering.Item;
            var helper = RenderingContext.Current.PageContext.HtmlHelper;



            var placeholders = new List <ReactPlaceholder>()
            {
            };


            return(PartialView(new DummyViewModel {
                Title = FieldRenderer.Render(item, "Title"), Text = FieldRenderer.Render(item, "Body"), Placeholders = placeholders
            }));
        }
Esempio n. 3
0
        public virtual FieldMapStatus Map(object modelInstance, Field field)
        {
            Model = modelInstance;
            Field = field;

            if (Property == null)
            {
                return(FieldMapStatus.NoProperty);
            }

            if (Property.GetCustomAttribute <DoNotMapAttribute>() != null)
            {
                return(FieldMapStatus.ExplicitIgnore);
            }

            if (Property.GetCustomAttribute <RawValueOnlyAttribute>() != null)
            {
                Property.SetValue(Model, Field.Value);
                return(FieldMapStatus.Success);
            }

            var paramsAttribute = Property.GetCustomAttribute <FieldRendererParamsAttribute>();

            if (paramsAttribute != null)
            {
                Property.SetValue(Model, FieldRenderer.Render(Field.Item, Field.Name, paramsAttribute.Params));
                return(FieldMapStatus.Success);
            }

            // Place to handle more complex scenarios.
            try
            {
                if (PropertyIsString())
                {
                    Property.SetValue(Model, ExtractStringValueFromField());
                    return(FieldMapStatus.Success);
                }

                return(FieldMapStatus.TypeMismatch);
            }
            catch (Exception ex)
            {
                Log.Error($"Failed to map Field {Field.Name} of Item {Field.Item.Name}", ex, this);
                return(FieldMapStatus.Exception);
            }
        }
        public string Render <TProperty>(Expression <Func <TDomainEntity, TProperty> > expression, FieldRendererArgs args)
        {
            var renderer = new FieldRenderer
            {
                Item       = GetItem(),
                FieldName  = GetFieldName(expression),
                Parameters = String.Join("&", GetParameters(args))
            };

            // maybe i'm losing it but if you want line breaks on multi-line text fields then you to add 'linebreaks'
            // to both Parameters and RenderParameters
            if (!string.IsNullOrEmpty(args.LineBreaks))
            {
                renderer.RenderParameters.Add("linebreaks", args.LineBreaks);
            }
            return(renderer.Render());
        }
        public virtual string Render(Item datasource, ID field, WebEditing canEdit = WebEditing.ReadOnly)
        {
            if (datasource == null)
            {
                throw new ArgumentNullException(nameof(datasource));
            }

            if (field.IsNull)
            {
                throw new ArgumentNullException(nameof(field));
            }

            var convertField     = field.ToString();
            var editingParameter = (canEdit == WebEditing.CanEdit) ? "disable-web-editing=false" : "disable-web-editing=true";

            return(FieldRenderer.Render(datasource, convertField, editingParameter));
        }
Esempio n. 6
0
        // GET: Default
        public ActionResult Index()
        {
            var page  = PageContext.Current.Item;
            var model = new HackathonModel
            {
                Title                 = page.Fields["Title"].Value,
                Description           = new HtmlString(FieldRenderer.Render(page, "Description")),
                SubmissionTitle       = page.Fields["Submission Title"].Value,
                SubmissionInformation = new HtmlString(FieldRenderer.Render(page, "Submission Information")),
                JudgesTitle           = page.Fields["Judges Title"].Value,
                PrizesTitle           = page.Fields["Prizes Title"].Value,
                PrizesDetail          = new HtmlString(FieldRenderer.Render(page, "Prizes Detail")),
                FAQsTitle             = page.Fields["FAQs Title"].Value
            };

            MultilistField judgesListInfo = page.Fields["Judges List"];

            foreach (var judge in judgesListInfo.GetItems())
            {
                LinkField twitterLink  = judge.Fields["Twitter Profile Link"];
                LinkField LinkedInLink = judge.Fields["LinkedIn Profile Link"];

                model.Judges.Add(new Judge
                {
                    Name            = judge.Fields["Name"].Value,
                    TwitterLink     = twitterLink.Url,
                    LinkedInLink    = LinkedInLink.Url,
                    Picture         = new HtmlString(FieldRenderer.Render(judge, "Picture")),
                    LinkedInPicture = new HtmlString(FieldRenderer.Render(judge, "LinkedIn Image")),
                    TwitterPicture  = new HtmlString(FieldRenderer.Render(judge, "Twitter Image")),
                });
            }

            MultilistField faqsListInfo = page.Fields["FAQs List"];

            foreach (var faq in faqsListInfo.GetItems())
            {
                model.FAQs.Add(new Faq
                {
                    Question = faq.Fields["Question"].Value,
                    Answer   = faq.Fields["Answer"].Value
                });
            }

            return(View("~/Views/Content/Pages/Hackathon.cshtml", model));
        }
Esempio n. 7
0
        public static List <Mate> GetTeamMates(Item item)
        {
            var teamMateItems = item.Axes.GetDescendants();
            var teamMates     = new List <Mate>();

            foreach (var teamMateItem in teamMateItems)
            {
                teamMates.Add(new Mate
                {
                    FullName = new HtmlString(FieldRenderer.Render(teamMateItem, "FullName")),
                    LinkedIn = teamMateItem.Fields["LinkedIn"].Value,
                    Twitter  = teamMateItem.Fields["Twitter"].Value,
                });
            }

            return(teamMates);
        }
Esempio n. 8
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                var parameters = new StringBuilder();

                if (processorContext.TryGetOption(DisableWebEditingOptionKey, out bool disableWebEditing))
                {
                    parameters.Append($"disable-web-editing={disableWebEditing}");
                }

                if (!pipelineContext.Faulted)
                {
                    switch (pipelineContext.Context)
                    {
                    case TextField field when processorContext.TryGetOption(RawFieldValue, out bool useRawFieldValue) && useRawFieldValue:
                        pipelineContext.Context = field.Value;

                        break;

                    case TextField field:
                        pipelineContext.Context = FieldRenderer.Render(field.InnerField.Item, field.InnerField.ID.ToString(), parameters.ToString());
                        break;

                    case ValueLookupField valueLookupField:
                        // Used for Unbound Droplist
                        pipelineContext.Context = valueLookupField.Value;
                        break;

                    default:
                        pipelineContext.Faulted = true;
                        break;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Esempio n. 9
0
        public void Save(object obj, string path)
        {
            using (new SecurityDisabler())
            {
                var item = database.GetItem(path);
                if (item != null)
                {
                    using (new EditContext(item))
                    {
                        foreach (var prop in obj.GetType().GetProperties())
                        {
                            if (prop.PropertyType == typeof(string))
                            {
                                item[GetFieldName(prop)] = prop.GetValue(obj).ToString();
                            }
                            else if (prop.PropertyType == typeof(Link))
                            {
                                Link lf = (Link)prop.GetValue(obj);
                                Sitecore.Data.Fields.LinkField field = item.Fields[GetFieldName(prop)];
                                if (field != null)
                                {
                                    lf.Assign(field);
                                }
                            }

                            else if (prop.PropertyType == typeof(Field <string>))
                            {
                                Field <string> fieldObj = (Field <string>)prop.GetValue(obj);

                                item[GetFieldName(prop)] = fieldObj.Data;
                                fieldObj.Render          = FieldRenderer.Render(item, GetFieldName(prop));
                            }
                            else if (prop.PropertyType == typeof(Field <Link>))
                            {
                                Field <Link> fieldObj = (Field <Link>)prop.GetValue(obj);

                                Sitecore.Data.Fields.LinkField lf = item.Fields[GetFieldName(prop)];
                                fieldObj.Data.Assign(lf);
                                fieldObj.Render = FieldRenderer.Render(item, GetFieldName(prop));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        public static MvcHtmlString Template <TModel, TValue>(this IPropellerTemplate <TModel> vm, Expression <Func <TModel, TValue> > expression)
        {
            if (Sitecore.Context.PageMode.IsExperienceEditor)
            {
                var expressionBody = expression.Body as System.Linq.Expressions.MethodCallExpression;
                try
                {
                    var getAsMethod = expressionBody.Arguments.FirstOrDefault() as MethodCallExpression;

                    var unaryExpression = getAsMethod.Arguments.FirstOrDefault() as UnaryExpression;
                    var innerExpresion  = unaryExpression.Operand as LambdaExpression;
                    var propertyField   = innerExpresion.Body as System.Linq.Expressions.MemberExpression;

                    var propName = propertyField.Member.Name;

                    var fullyQualifiedName = typeof(TModel).FullName;

                    var key = $"{fullyQualifiedName}.{propName}";

                    Func <ID> idFunc;
                    if (MappingTable.Instance.JumpMap.TryGetValue(key, out idFunc))
                    {
                        var fieldId = idFunc();

                        var htmlStr = FieldRenderer.Render(vm.DataItem, fieldId.ToString());
                        return(new MvcHtmlString(htmlStr));
                    }



                    return(new MvcHtmlString("sd"));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                var result = expression.Compile();
                var value  = result(vm.TemplateArg());
                var r      = new MvcHtmlString(value.ToString());
                return(r);
            }
        }
Esempio n. 11
0
        // GET: Overview
        public ActionResult Index()
        {
            var model = new OverviewList();

            model.AddRange(RenderingContext.Current.ContextItem.GetChildren(Sitecore.Collections.ChildListOptions.SkipSorting)
                           .OrderBy(i => i.Created)
                           .Select(i => new OverviewItem()
            {
                URL            = LinkManager.GetItemUrl(i),
                ContentHeading = new HtmlString(FieldRenderer.Render(i, "contentheading")),
                EventImage     = new HtmlString(FieldRenderer.Render(i, "decorationbanner", "mw=500&mh=333"))
            })

                           );


            return(View(model));
        }
Esempio n. 12
0
        public static string Render(string key, bool disableWebEditing)
        {
            var entry = FindEntry(key);

            if (entry == null)
            {
                return("#" + key + "#");
            }

            if (disableWebEditing)
            {
                return(FieldRenderer.Render(entry, PHRASE, "disable-web-editing=true"));
            }
            else
            {
                return(FieldRenderer.Render(entry, PHRASE));
            }
        }
        public string Rendered(int?maxWidth, int?maxHeight)
        {
            SafeDictionary <string> parameters = new SafeDictionary <string>();

            if (maxWidth.HasValue)
            {
                parameters.Add("mw", maxWidth.Value.ToString());
            }
            if (maxHeight.HasValue)
            {
                parameters.Add("mh", maxHeight.Value.ToString());
            }
            if (this.field == null)
            {
                return(string.Empty);
            }
            return(FieldRenderer.Render(this.item, this.field.InnerField.Name, WebUtil.BuildQueryString(parameters, false)));
        }
Esempio n. 14
0
 public void Initialize(Sitecore.Mvc.Presentation.Rendering rendering)
 {
     Item      = rendering.Item;
     isSetDs   = rendering.DataSource;
     Rendering = Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering;
     if (!String.IsNullOrEmpty(isSetDs))
     {
         try {
             smallHeadline = FieldRenderer.Render(Item, "Small Headline");
             largeHeadline = FieldRenderer.Render(Item, "Large Headline");
             headline      = FieldRenderer.Render(Item, "Headline");
         }
         catch
         {
             isSetDs = "";
         }
     }
 }
Esempio n. 15
0
        public static List <Team> GetTeams(Item item)
        {
            var teamChildren = item.Children;
            var teams        = new List <Team>();

            foreach (var teamChild in teamChildren.InnerChildren)
            {
                var teamItem = Sitecore.Context.Database.GetItem(teamChild.ID);
                teams.Add(new Team
                {
                    Country   = GetCountry(teamItem),
                    TeamName  = new HtmlString(FieldRenderer.Render(teamItem, "TeamName")),
                    TeamMates = GetTeamMates(teamItem)
                });
            }

            return(teams);
        }
        private OverviewList GetModel()
        {
            var children = RenderingContext.Current.ContextItem.GetChildren(Sitecore.Collections.ChildListOptions.SkipSorting)
                           .OrderBy(i => i.Created)
                           .Select(i => new OverviewItem
            {
                URL   = LinkManager.GetItemUrl(i),
                Title = new HtmlString(FieldRenderer.Render(i, "ContentHeading")),
                Image = new HtmlString(FieldRenderer.Render(i, "DecorationBanner", "mw=500&mh=333")),
            });
            var model = new OverviewList
            {
                ReadMore = Translate.Text("Read More")
            };

            model.AddRange(children);
            return(model);
        }
Esempio n. 17
0
        private string RenderPhraseItem(string key, Item item, bool editable)
        {
            if (this.IsInEditingMode && editable)
            {
                if (item != null)
                {
                    var renderer = new FieldRenderer
                    {
                        Item      = item,
                        FieldName = this.setting.DictionaryPhraseFieldName
                    };

                    return(renderer.Render());
                }
            }

            return(item?[this.setting.DictionaryPhraseFieldName] ?? key);
        }
Esempio n. 18
0
        private string GetSearchBoxPlaceholderText(string q, Item sitecoreItem)
        {
            if (q.IsNotNullAndNotWhiteSpace())
            {
                return(q);
            }
            else
            {
                using (var fr = new FieldRenderer())
                {
                    fr.Item              = sitecoreItem;
                    fr.FieldName         = Global_Search_Constants.Keywords_Textbox_Watermark_FieldName;
                    fr.DisableWebEditing = true;

                    return(fr.Render());
                }
            }
        }
        private static EventIntro CreateModel()
        {
            var item = RenderingContext.Current.ContextItem;

            var eventIntro = new EventIntro()
            {
                Heading    = new HtmlString(FieldRenderer.Render(item, "ContentHeading")),
                EventImage = new HtmlString(FieldRenderer.Render(item, "Event Image", "mw=400")),
                Body       = new HtmlString(FieldRenderer.Render(item, "ContentBody")),
                Highlights = new HtmlString(FieldRenderer.Render(item, "Highlights")),
                Intro      = new HtmlString(FieldRenderer.Render(item, "ContentIntro")),
                StartDate  = new HtmlString(FieldRenderer.Render(item, "Start Date")),
                Duration   = new HtmlString(FieldRenderer.Render(item, "Duration")),
                Difficulty = new HtmlString(FieldRenderer.Render(item, "Difficulty Level")),
            };

            return(eventIntro);
        }
Esempio n. 20
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                string parameters = string.Empty;

                if (processorContext.Options.ContainsKey(CssClass))
                {
                    parameters = AddParameter(parameters, $"class={processorContext.Options[CssClass]}");
                }

                if (processorContext.Options.ContainsKey(Width) &&
                    int.TryParse(processorContext.Options[Width].ToString(), out int width))
                {
                    parameters = AddParameter(parameters, $"w={width}");
                }

                if (processorContext.Options.ContainsKey(Height) &&
                    int.TryParse(processorContext.Options[Height].ToString(), out int height))
                {
                    parameters = AddParameter(parameters, $"h={height}");
                }

                switch (pipelineContext.Context)
                {
                case CustomField customField:
                    pipelineContext.Context = FieldRenderer.Render(customField.InnerField.Item, customField.InnerField.ID.ToString(), parameters);
                    break;

                default:
                    pipelineContext.Faulted = true;
                    break;
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Esempio n. 21
0
        public IHtmlString Field <TModel>(TModel model, Expression <Func <TModel, CustomField> > fieldFunc)
        {
            var property = fieldFunc.Compile()(model);

            var memberExpression = fieldFunc.Body as MemberExpression;
            var propertyInfo     = memberExpression?.Member as PropertyInfo;

            if (propertyInfo == null)
            {
                return(null);
            }

            if (Convert.ChangeType(property, propertyInfo.PropertyType) is CustomField propertyValue)
            {
                return(propertyValue.InnerField.HasValue ? new HtmlString(FieldRenderer.Render(propertyValue.InnerField.Item, propertyValue.InnerField.Name)) : null);
            }

            return(null);
        }
        /// <summary>
        /// Judges Information Section
        /// </summary>
        /// <returns></returns>
        public ActionResult RenderJudgesInfoSection()
        {
            var currentItem  = RenderingContext.Current.Rendering.Item;
            var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
            var dataSource   = Sitecore.Context.Database.GetItem(dataSourceId);

            if (dataSource != null)
            {
                var judgeinformation = dataSource.Fields["JudgesInformation"]?.Value;
                Sitecore.Data.Fields.MultilistField multiselectField =
                    dataSource.Fields["JudgesList"];
                Sitecore.Data.Items.Item[] items = multiselectField.GetItems();

                if (items != null && items.Length > 0)
                {
                    var listofjudges = new List <JudgesDetails>();
                    for (int i = 0; i < items.Length; i++)
                    {
                        Sitecore.Data.Items.Item judgeItem = items[i];

                        Sitecore.Data.Fields.ImageField field = items[i].Fields["JudgesPic"];

                        var judgedetail = new JudgesDetails()
                        {
                            JudgesInfo       = FieldRenderer.Render(judgeItem, "JudgesInfo"),
                            JudgeName        = FieldRenderer.Render(judgeItem, "JudgeName"),
                            JudgesProfession = FieldRenderer.Render(judgeItem, "JudgesProfession"),
                            JudgesPic        = MediaManager.GetMediaUrl(field.MediaItem)
                        };
                        listofjudges.Add(judgedetail);
                    }
                    var returnviewmodel = new JudgesViewModel()
                    {
                        JudgesList        = listofjudges,
                        JudgesInformation = judgeinformation
                    };

                    return(View("~/Views/JudgesInformation/JudgesInformation.cshtml", returnviewmodel));
                }
                ;
            }
            return(View("~/Views/JudgesInformation/JudgesInformation.cshtml", null));
        }
Esempio n. 23
0
        // GET: Overview
        public ActionResult Index()
        {
            var oList = new OverviewList();

            oList.ReadMore = "Read More";

            var contextItem = RenderingContext.Current.ContextItem;

            oList.AddRange(contextItem.GetChildren()
                           .Select(a => new OverviewItem()
            {
                Title = new HtmlString(a.DisplayName),     // book shows fieldrenderer
                URL   = LinkManager.GetItemUrl(a),
                Image = new HtmlString(FieldRenderer.Render(a, "decorationbanner", "mw=500&mh=333")),
            }));


            return(View(oList));
        }
        /// <summary>
        /// Previous Years Snapshot Section
        /// </summary>
        /// <returns></returns>
        public ActionResult RenderPastYearSnapshotSection()
        {
            var currentItem  = RenderingContext.Current.Rendering.Item;
            var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
            var dataSource   = Sitecore.Context.Database.GetItem(dataSourceId);

            if (dataSource != null)
            {
                var previousyearinformation = dataSource.Fields["PreviousYearSnapshotTitle"]?.Value;
                Sitecore.Data.Fields.MultilistField multiselectField =
                    dataSource.Fields["PreviousYearSnapshotList"];
                Sitecore.Data.Items.Item[] items = multiselectField.GetItems();

                if (items != null && items.Length > 0)
                {
                    var listofsnapshot = new List <PreviousYearSnapshotDetails>();
                    for (int i = 0; i < items.Length; i++)
                    {
                        Sitecore.Data.Items.Item snapshotItem = items[i];

                        Sitecore.Data.Fields.ImageField field = items[i].Fields["PreviousYearImage"];

                        var snapshotdetail = new PreviousYearSnapshotDetails()
                        {
                            PreviousYearTitle       = FieldRenderer.Render(snapshotItem, "PreviousYearTitle"),
                            PreviousYear            = FieldRenderer.Render(snapshotItem, "PreviousYear"),
                            PreviousYearDescription = FieldRenderer.Render(snapshotItem, "PreviousYearDescription"),
                            PreviousYearImage       = MediaManager.GetMediaUrl(field.MediaItem)
                        };
                        listofsnapshot.Add(snapshotdetail);
                    }
                    var returnviewmodel = new PastYearSnapshotViewModel()
                    {
                        PreviousYearSnapshotTitle = previousyearinformation,
                        PreviousYearSnapshotList  = listofsnapshot
                    };

                    return(View("~/Views/PreviousYear/PreviousYear.cshtml", returnviewmodel));
                }
                ;
            }
            return(View("~/Views/PreviousYear/PreviousYear.cshtml", null));
        }
        public static EventIntro CreateModel()
        {
            var item = RenderingContext.Current.ContextItem;
            int diffLevel;

            return(new EventIntro()
            {
                ContentHeading = new HtmlString(FieldRenderer.Render(item, "ContentHeading")),
                ContentBody = new HtmlString(FieldRenderer.Render(item, "ContentBody")),
                EventImage = new HtmlString(FieldRenderer.Render(item, "EventImage", "mw=400")),
                Highlights = new HtmlString(FieldRenderer.Render(item, "Highlights")),
                ContentIntro = new HtmlString(FieldRenderer.Render(item, "ContentIntro")),
                StartDate = new HtmlString(FieldRenderer.Render(item, "StartDate")),
                Duration = new HtmlString(FieldRenderer.Render(item, "Duration")),
                DifficultyLevel = int.TryParse(item.Fields["DifficultyLevel"].Value, out diffLevel)
                    ? diffLevel
                    : 0
            });
        }
        public static string Render(this Field field, string parameters)
        {
            Assert.ArgumentNotNull(field, "field");

            if (string.IsNullOrEmpty(field.Value))
            {
                return(string.Empty);
            }

            if (!ShouldRender(field))
            {
                return(field.Value);
            }

            return(FieldRenderer.Render(
                       field.Item,
                       field.ID.ToString(),
                       parameters));
        }
Esempio n. 27
0
        // GET: Overview
        public ActionResult Index()
        {
            var model = new OverviewList()
            {
                ReadMore = Sitecore.Globalization.Translate.Text("Read More")
            };

            model.AddRange(RenderingContext.Current.ContextItem.GetChildren(ChildListOptions.SkipSorting)
                           //.OrderBy(i=>i.Modified)
                           .OrderBy(i => i.Created)
                           .Select(i => new OverviewItem()
            {
                Url   = LinkManager.GetItemUrl(i),
                Title = new HtmlString(FieldRenderer.Render(i, FieldNameTitle)),
                Image = new HtmlString(FieldRenderer.Render(i, FieldNameImage, "mw=500&mh=333&class=img-responsive"))
            }
                                   ));
            return(View(model));
        }
Esempio n. 28
0
 /// <summary>
 /// Gets field value from item with page editor support, and parameters for the field renderer
 /// </summary>
 /// <param name="item">Sitecore item</param>
 /// <param name="fieldName">Field name</param>
 /// <param name="pageEditorSupport">True if page editor support is required, otherwise false</param>
 /// <param name="attributes">Field renderer parameters</param>
 /// <returns>Field value or field renderer rendered control</returns>
 public static string GetFieldValue(this Item item, string fieldName, bool pageEditorSupport = false, IDictionary <string, string> attributes = null)
 {
     if (pageEditorSupport)
     {
         var fieldRenderer = new FieldRenderer();
         fieldRenderer.Item      = item;
         fieldRenderer.FieldName = fieldName;
         if (attributes != null)
         {
             fieldRenderer.Parameters = string.Join("&",
                                                    attributes.Keys.Select(k => string.Format("{0}={1}", k, attributes[k])));
         }
         return(fieldRenderer.Render());
     }
     else
     {
         var field = item.Fields[fieldName];
         return(field != null ? field.Value : string.Empty);
     }
 }
Esempio n. 29
0
        private HeroContent CreateModel()
        {
            var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
            var item         = Sitecore.Context.Database.GetItem(dataSourceId);

            var heroContent = new HeroContent()
            {
                Title               = new HtmlString(FieldRenderer.Render(item, "Title")),
                SubTitle            = new HtmlString(FieldRenderer.Render(item, "SubTitle")),
                Description         = new HtmlString(FieldRenderer.Render(item, "Description")),
                LinkMoreInformation = new HtmlString(FieldRenderer.Render(item, "LinkMoreInformation")),
                LinkJoin            = new HtmlString(FieldRenderer.Render(item, "LinkJoin")),
                BackgroundImage     = LinkUtil.GetUrlFromLinkField(item.Fields["BackgroundImage"]),
                VideoUrl            = LinkUtil.GetUrlFromLinkField(item.Fields["VideoUrl"]),
                MainEventDate       = ((DateField)item.Fields["MainEventDate"]).DateTime.ToString(),
                LabelDaysLeft       = new HtmlString(FieldRenderer.Render(item, "LabelDaysLeft")),
            };

            return(heroContent);
        }
        private static string ReplaceTokens(string fieldValue, Match match, RenderFieldArgs args)
        {
            XElement xElement = XElement.Parse(match.ToString());

            if (xElement.Attribute("field") != null &&
                xElement.Attribute("item") != null)
            {
                string item  = xElement.Attribute("item").Value;
                string field = xElement.Attribute("field").Value;

                Item tokenItem = Context.Database.GetItem(item);

                // Check the token rendering does not go in infinite loop
                if (tokenItem != null && !(tokenItem.ID == args.Item.ID && string.Equals(field, args.FieldName, System.StringComparison.OrdinalIgnoreCase)))
                {
                    fieldValue = fieldValue.Replace(match.ToString(), FieldRenderer.Render(tokenItem, field));
                }
            }
            return(fieldValue);
        }
	    /// <summary>
	    /// Gets translated phrase for context language by specified translation key.
	    /// With option of formatting like string.Format() method functionality.
	    /// Dictionary entry item will be created if it doesn't exist with default phrase value 
	    /// equals to passed parameter (or it will be equal to translation key in case default value is null or empty).
	    /// </summary>
	    /// <param name="key">The key.</param>
	    /// <param name="defaultValue">The default value.</param>
	    /// <param name="language"></param>
	    /// <param name="formatParams">The format params.</param>
	    /// <returns>System.String.</returns>
	    public virtual string Text(string key, string defaultValue, Language language, params object[] formatParams)
        {
            try
            {
                if (string.IsNullOrEmpty(key))
                {
                    return string.Empty;
                }

				var translationItem = GetTranslationItem(key, defaultValue, language ?? Context.Language);

                if (translationItem == null)
                {
                    return string.Empty;
                }

                var fieldRenderer = new FieldRenderer
                {
                    Item = translationItem,
                    FieldName = Constants.DICTIONARY_ENTRY_PHRASE_FIELD_NAME,
                };

                var result = fieldRenderer.Render();

                if (formatParams != null && formatParams.Length > 0 && !_siteContext.IsPageEditor)
                {
                    return string.Format(result, formatParams);
                }

                return result;
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error during translating the key '{0}'. {1}", key, ex.Message), ex, this);

                return string.Empty;
            }
        }
Esempio n. 32
0
    /// <summary>
    /// Gets the FLD from database.
    /// </summary>
    /// <param name="fieldName">Name of the field.</param>
    /// <param name="databaseName">Name of the database.</param>
    /// <param name="iterator">The iterator.</param>
    /// <returns></returns>
    public string GetFldFromDatabase(string fieldName, string databaseName, XPathNodeIterator iterator)
    {
      ID id;
      if (!iterator.MoveNext())
      {
        return null;
      }

      if (!ID.TryParse(iterator.Current.GetAttribute("id", string.Empty), out id))
      {
        return null;
      }

      Database database = Factory.GetDatabase(databaseName);
      if (database == null)
      {
        return null;
      }

      Item itm = ItemManager.GetItem(id, Language.Current, Sitecore.Data.Version.Latest, database);

      var renderer = new FieldRenderer
      {
        Item = itm,
        FieldName = fieldName
      };
      return renderer.Render();
    }
Esempio n. 33
0
      private static string RenderTags(ClientPipelineArgs args) 
      {
        Assert.ArgumentNotNull(args, "args");
        string result = args.Result;
        string str3 = args.Parameters["itemid"];
        string name = args.Parameters["language"];
        string str5 = args.Parameters["version"];
        string str6 = args.Parameters["fieldid"];
        string currentValue = "|" + args.Parameters["currentValue"] + "|";

        Item item = Context.ContentDatabase.GetItem(ID.Parse(str3), Language.Parse(name), Sitecore.Data.Version.Parse(str5));
        if (item == null)
        {
          SheerResponse.Alert("The item was not found.\n\nIt may have been deleted by another user.", new string[0]);
          return null;
        }
        Field field = item.Fields[ID.Parse(str6)];
        if (field == null)
        {
          SheerResponse.Alert("The field was not found.\n\nIt may have been deleted by another user.", new string[0]);
          return null;
        }

        string newTag = string.Format("{0}:{1}", result, "{C1453A1D-9ED2-428A-8BB3-50B4A877BEA7}");
        if (args.Parameters["mode"] == "check")
        {
          string tagNotFound = string.Format("|{0}:{1}|", ID.Null, args.Parameters["tagNotFound"]);
          currentValue = args.HasResult && args.Result != "undefined" ? currentValue.Replace(tagNotFound, "|" + newTag + "|") : currentValue.Replace(tagNotFound, "|");
        }
        else
        {
          currentValue += string.Format("{0}|", newTag);
        }

        currentValue = currentValue.Trim("|".ToCharArray());
        args.Parameters["currentValue"] = currentValue;

        FieldRenderer renderer = new FieldRenderer();
        renderer.Item = item;
        renderer.FieldName = field.Name;
        renderer.OverrideFieldValue(currentValue);
        renderer.DisableWebEditing = false;
        return renderer.Render();         
      }
Esempio n. 34
0
        public override string GetFieldValue(DataRow dr, string fieldidentifier, string before, string after, string parameters)
        {
            string result = string.Empty;

            // Try to get the value directly from the sitecore item if possible,
            // otherwise just use the value in the DataRow
            if (!IsSpecialField(fieldidentifier) && dr.Table.Columns.Contains("_ItemId"))
            {
                Item item = this.InnerItem.Database.GetItem(new ID((string)dr["_ItemId"]));

                var fieldID = string.Empty;
                if (Sitecore.Data.ID.IsID(fieldidentifier))
                    fieldID = fieldidentifier;
                else if (dr.Table.Columns.Contains(fieldidentifier))
                    fieldID = (string)dr.Table.Columns[fieldidentifier].ExtendedProperties["_FieldKey"];
                else
                {
                    Log.Info(string.Format("ItemDataset does not contain the field. [ds:{0}][field:{1}]", this.InnerItem.Paths.Path, fieldidentifier), this);
                    return string.Empty;
                }

                if (item[fieldID].IsNullOrEmpty())
                    result = item.RenderField(fieldID, parameters);
                else
                {
                    FieldRenderer fr = new FieldRenderer();
                    fr.Before = before;
                    fr.After = after;
                    fr.Parameters = parameters;
                    fr.FieldName = fieldID;
                    fr.Item = item;
                    result = fr.Render();
                }
            }
            else
            {
                result = dr[fieldidentifier].ToString();
            }

            return result;
        }
        /// <summary>
        /// The render.
        /// </summary>
        /// <param name="field">
        /// The field.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <param name="enclosingTag">
        /// The enclosing tag.
        /// </param>
        /// <param name="before">
        /// The before.
        /// </param>
        /// <param name="after">
        /// The after.
        /// </param>
        /// <param name="disableWebEdit">
        /// The disable web edit.
        /// </param>
        /// <returns>
        /// The <see cref="HtmlString"/>.
        /// </returns>
        public static HtmlString Render(
            this CustomField field, 
            string parameters, 
            string enclosingTag, 
            string before, 
            string after, 
            bool disableWebEdit = false)
        {
            if (field == null || field.InnerField == null || field.InnerField.Item == null)
            {
                return new HtmlString(string.Empty);
            }

            var renderer = new FieldRenderer()
                               {
                                   Item = field.InnerField.Item, 
                                   FieldName = field.InnerField.Name, 
                                   Parameters = parameters, 
                                   EnclosingTag = enclosingTag, 
                                   Before = before, 
                                   After = after, 
                                   DisableWebEditing = disableWebEdit
                               };

            return new HtmlString(renderer.Render());
        }
Esempio n. 36
-1
        protected override void GetSummary(GetSummaryArgs args)
        {
            var renderer = new FieldRenderer();
            renderer.Item = args.Entry;
            renderer.FieldName = FieldName;

            args.Summary = renderer.Render();
        }
Esempio n. 37
-1
 /// <summary>
 /// Gets the content of the field.
 /// </summary>
 /// <param name="editable">if set to <c>true</c> [editable].</param>
 /// <returns>System.String.</returns>
 private string GetFieldContent(bool editable = true)
 {
     FieldRenderer render = new FieldRenderer();
     render.FieldName = _fieldName;
     render.Item = _item;
     render.DisableWebEditing = !editable;
     return render.Render();
 }
        public static string GetString(Item item, string fieldName, bool ignoreCase)
        {
            var field = item.Fields[fieldName];

            if (field == null) return string.Empty;

            FieldRenderer render = new FieldRenderer();
            render.Item = item;
            render.FieldName = field.Name;
            render.DisableWebEditing = !EditMode.UseEditMode;
            return render.Render();
        }
 public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
 {
     if (item.Fields[FieldName] != null && item.Fields[FieldName].Type.StartsWith("Rich Text") && Setting != SitecoreFieldSettings.RichTextRaw)
     {
         FieldRenderer renderer = new FieldRenderer();
         renderer.Item = item;
         renderer.FieldName = FieldName;
         renderer.Parameters = string.Empty;
         return renderer.Render();
     }
     else return item[FieldName];
 }
        public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
        {
            var field = base.GetField(item);

            if (field == null)
                return string.Empty;

            if (field.Type.StartsWith("Rich Text") && Setting != SitecoreFieldSettings.RichTextRaw)
            {
                FieldRenderer renderer = new FieldRenderer();
                renderer.Item = item;
                renderer.FieldName = field.Name;
                renderer.Parameters = string.Empty;
                return renderer.Render();
            }
            else return field.Value ;
        }
        /// <summary>
        /// Gets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            if (field == null)
                return string.Empty;

            if (config.Setting == SitecoreFieldSettings.RichTextRaw)
                return field.Value;

            if (field.Type.StartsWith("Rich Text"))
            {
                FieldRenderer renderer = new FieldRenderer();
                renderer.Item = field.Item;
                renderer.FieldName = field.Name;
                renderer.Parameters = string.Empty;
                return renderer.Render();
            }
            else return field.Value;
        }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;

            string name = binder.Name;


            if (_item.Fields[name] != null)
            {
                FieldRenderer render = new FieldRenderer();
                render.FieldName = name;
                render.Item = _item;

                result = render.Render();
                return true;
            }

            SitecoreInfoType infoType;

            if (Enum.TryParse<SitecoreInfoType>(name, out infoType))
            {
                result = SitecoreInfoHandler.GetItemInfo(infoType, _item, null);
                return true;
            }


            switch (name)
            {
                case "Parent":
                    result = new DynamicItem(_item.Parent);
                    break;
                case "Children":
                    result = new DynamicCollection<DynamicItem>(_item.Children.Select(x => new DynamicItem(x)).ToArray());
                    break;
            }
            if (result != null) return true;
            
            throw new NotSupportedException("No field of Sitecore info matches the name {0} for item {1}".Formatted(name, _item.Paths.FullPath));

        }