GraffitiCMS View Overrides Part II

Monday, February 08 2010 -

In a previous post I wrote about the naming conventions used by GraffitiCMS for view overrides.

For more details on how this works take a look at the below code from the CategoryPage.cs

protected override string ViewLookUp(string baseName, string defaultViewName)

        {

            Category category = new CategoryController().GetCachedCategory(CategoryID, false);

 

            // category-name.view

            if (category.ParentId <= 0 && ViewExists(CategoryName + baseName))

                return CategoryName + baseName;

 

            // Subcategories

            if (category.ParentId > 0)

            {

                // parent-name.child-name.view

                if (ViewExists(category.LinkName.Replace("/", ".") + baseName))

                    return category.LinkName.Replace("/", ".") + baseName;

 

                // childcategory.parent-name.view

                if (ViewExists("childcategory." + category.Parent.LinkName + baseName))

                    return "childcategory." + category.Parent.LinkName + baseName;

 

                // childcategory.view

                if (ViewExists("childcategory" + baseName))

                    return "childcategory" + baseName;

 

                // parent-name.view

                if (ViewExists(category.Parent.LinkName + baseName))

                    return category.Parent.LinkName + baseName;

            }

 

            // category.view

            if (ViewExists("category" + baseName))

                return "category" + baseName;

 

            // index.view

            return base.ViewLookUp(baseName, defaultViewName);

 

        }