Exemple #1
0
        /// <summary>
        /// Creates a Virtual Path to the view associated with the RenderingItem associated with this instance.
        /// Uses RenderingItemPathRoot and ViewRootPath to establish the valid part of the path from Sitecore as well
        /// as the starting point for the virtual path.
        /// </summary>
        /// <returns>The virtual path to the view.</returns>
        public string ResolveViewPath()
        {
            var area          = RenderingItem.InnerItem["Area"];
            var viewRoot      = ViewRootPath;
            var renderingRoot = RenderingItemPathRoot;

            if (!string.IsNullOrEmpty(area))
            {
                renderingRoot = renderingRoot.Replace("$Area", area).ToLower();
                viewRoot      = viewRoot.Replace("$Area", area).ToLower();
            }

            var path          = NameConverter.ConvertItemPathToClassPath(RenderingItem.InnerItem.Paths.FullPath).ToLower();
            var truncatedPath = path.Replace(renderingRoot, string.Empty);

            var viewLocation = viewRoot + truncatedPath + ".cshtml";

            return(viewLocation);
        }
        /// <inheritdoc />
        public string ResolveViewPath(RenderingItem renderingItem)
        {
            var area          = renderingItem.InnerItem["Area"];
            var viewRoot      = ViewRootPath.ToLower();
            var renderingRoot = RenderingItemPathRoot.ToLower();

            if (!string.IsNullOrEmpty(area))
            {
                renderingRoot = renderingRoot.Replace("$area", area).ToLower();
                viewRoot      = viewRoot.Replace("$area", area).ToLower();
            }

            // We need to figure out if there's a Helix folder in the Rendering path and ensure it gets removed from the View's path.
            // Helix folders don't show up in View Paths because MVC Areas aren't complex enough to support it.
            var fullPath = renderingItem.InnerItem.Paths.FullPath;

            if (fullPath.Contains("/Foundation/"))
            {
                renderingRoot = renderingRoot.Replace("$helix", "foundation");
            }

            if (fullPath.Contains("/Feature/"))
            {
                renderingRoot = renderingRoot.Replace("$helix", "feature");
            }

            if (fullPath.Contains("/Project/"))
            {
                renderingRoot = renderingRoot.Replace("$helix", "project");
            }

            var path = NameConverter.ConvertItemPathToClassPath(fullPath).ToLower();

            var truncatedPath = path.Replace(renderingRoot, string.Empty);

            var viewLocation = viewRoot + truncatedPath + ".cshtml";

            return(viewLocation);
        }