Example #1
0
        protected new virtual Item ResolveItem(GetPageItemArgs args)
        {
            string path = this.GetPath(args.RouteData);

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            Item wildcardItem = this.GetItem(path, args);

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

            if (!WildCardProvider.IsWildcardItem(wildcardItem))
            {
                return(wildcardItem);
            }

            ReferenceField datasourceReference = wildcardItem.Fields[Templates.WildCard.Fields.WildCardDatasourceField];

            if (datasourceReference == null || datasourceReference.TargetItem == null)
            {
                return(wildcardItem);
            }

            if (HttpContext.Current.Items.Contains(Templates.WildCard.Fields.ContextItemKey))
            {
                HttpContext.Current.Items[Templates.WildCard.Fields.ContextItemKey] = wildcardItem;
            }
            else
            {
                HttpContext.Current.Items.Add(Templates.WildCard.Fields.ContextItemKey, wildcardItem);
            }

            string itemRelativePath = StringUtil.EnsurePrefix('/', WildCardProvider.GetWildCardItemRelativeSitecorePathFromUrl(path, wildcardItem));
            string itemPath         = string.Concat(datasourceReference.TargetItem.Paths.FullPath, itemRelativePath);

            string[] pathSegments = itemPath.Split('/');
            return(WildCardProvider.GetDatasourceItem(string.Join("/", pathSegments.Take(pathSegments.Length - 1)), pathSegments.LastOrDefault()));
        }
Example #2
0
        public override void Process(HttpRequestArgs args)
        {
            // WildCard Item: Only handler wildcard item.
            if (!WildCardProvider.IsWildcardItem(Context.Item))
            {
                return;
            }

            string itemName       = ResolveItemNameFromUrl(args.HttpContext);
            var    datasourceItem = WildCardProvider.GetDatasourceItem(Context.Item, itemName);

            if (datasourceItem == null)
            {
                return;
            }

            args.HttpContext.Items[Templates.WildCard.Fields.ContextItemKey] = Context.Item;
            Context.Item = datasourceItem;
        }