U4-2810 - Allow Icons to be set at both Document Level and Content Level

Created by Anton Pham 08 Sep 2013, 07:52:46 Updated by Shannon Deminick 21 Jun 2017, 07:58:15

Currently icons can only be set at the document level. Although its good to have a generic place to define an icon it would be even better if the icon can be defined at the content level thus overriding the document icon.

We have a use case where there is a DocType called "CountryLandingPage" - By definition this doctype is used for each of the countries that we want to create in the content tree. As you can imagine, we would like to assign a country flag to each of the countries for a better editor experience.

Now, we solve this problem by creating many "Dummy" doctypes for each country. This is quite cumbersome especially if the editor wants to add a new country - The developer is required to create the doctype.

Thanks.

1 Attachments

Comments

Funka! 09 Sep 2013, 18:14:20

Hi Anton,

I wanted to make a suggestion that for your particular needs, you might find it possible to plug in this functionality yourself with minimum C# coding required. Umbraco makes it easy to plug in and override which icon gets drawn in the tree, so you could do something that uses the name of the node as part of the filename. For example you could have a big folder of all your images named US.png, AU.png, FR.png, etc... and then on your country-type documents, take the name of the node + ".png" to know which icon to use.

There is an excellent package called [http://our.umbraco.org/projects/backoffice-extensions/media-icons Media Icons] for which there is also [https://bitbucket.org/mattbrailsford/mediaicons source code] available, which shows a great example of how to do this. I'd recommend downloading this and see how it works, and see if you think you might be able to do what you're asking for your content tree. At the very least, you'd have something easier for your editors to use and avoid any incorrect icon-assignments. Good luck!


Anton Pham 10 Sep 2013, 02:55:47

Thanks - I had a similar thought but wasn't sure where to get started. Let me look into that.


Anton Pham 10 Sep 2013, 06:43:31

We hacked something together along these lines:

public class RenderCountryFlagEvent : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { BaseTree.BeforeNodeRender += BaseTree_BeforeNodeRender; }

    void BaseTree_BeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, System.EventArgs e)
    {
        try
        {
            Node contentNode = new Node(int.Parse(node.NodeID));

            var template = umbraco.cms.businesslogic.template.Template.GetTemplate(contentNode.template);
            if (template != null && template.Alias == "CountryLandingPage")
            {
                var iconUrl = string.Format("flag_{0}.png", contentNode.Name);
                node.Icon = iconUrl;
            }
        }
        catch (Exception)
        {
            node.Icon = "world.png";
        }
    }
}


Shannon Deminick 21 Jun 2017, 07:58:15

Closing issue due to inactivity - see blog post for details https://umbraco.com/blog/issue-tracker-cleanup/


Priority: Normal

Type: Feature (request)

State: Closed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version:

Sprint:

Story Points:

Cycle: