Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Warren Buckley 2089 posts 4578 karma points MVP ∞ admin hq c-trib
    Jun 24, 2013 @ 08:20
    Warren Buckley
    0

    How do I replace the stylesheets tree with my own custom CSS tree

    I am working on a package and have written a class that inherits from BaseTree and uses the Data attributes to decorate the class to get it automatically registered as a tree on app startup by umbraco. 

    I can register this as a new tree perfectly fine, but I would like to replace the CSS tree with my own custom CSS tree class that I have written. Is this possible without modifying the core?

    Thanks, warren 

  • Anders Bjerner 448 posts 2601 karma points MVP 4x admin c-trib
    Jun 24, 2013 @ 21:58
    Anders Bjerner
    0

    You can alter the trees through the class TreeDefinitionCollection. The code below is executed when the applications starts, and will remove the the "stylesheets" tree. I don't see a way to replace the tree, but you should be able to add your own tree at the same location by giving your tree the same sort value as the deleted tree.

    public class ExampleEventHandler : ApplicationEventHandler {

        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) {
            
            var stylesheets = TreeDefinitionCollection.Instance.FirstOrDefault(x => x.App.alias.ToLower() == "settings" && x.Tree.Alias.ToLower() == "stylesheets");
            if (stylesheets != null) TreeDefinitionCollection.Instance.Remove(stylesheets);

        }

    }
  • Sean Mooney 131 posts 158 karma points c-trib
    Jun 24, 2013 @ 22:27
    Sean Mooney
    0

    You should be able to replace the existing tree by modifing /config/trees.config

    <add application="settings" alias="stylesheets" title="Stylesheets" type="umbraco.loadStylesheets, umbraco" iconClosed=".sprTreeFolder" iconOpen=".sprTreeFolder_o" sortOrder="0" />

    Change the "type" proptery to point to your custom tree, that should replace the existing Stylesheets tree with your new one

  • Anders Bjerner 448 posts 2601 karma points MVP 4x admin c-trib
    Jun 25, 2013 @ 12:35
    Anders Bjerner
    0

    You can archieve pretty much the same with either method. However for a package I believe its best not to touch the config files if possible.

  • David Brendel 786 posts 2949 karma points c-trib
    Jun 25, 2013 @ 13:12
    David Brendel
    0

    I think it's ok to replace the type in the config file. If it's only for your own project than definetly.

    If you would use the custom tree in a package than you have to make sure that an uninstall also reverts to the correct type so that the old css tree will work again.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies