Copied to clipboard

Flag this post as spam?

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


  • Johan Möller 83 posts 137 karma points
    Apr 09, 2010 @ 10:18
    Johan Möller
    0

    Changing node icon depending on language

    Hi, so far ive been using icon picker to get a flag icon depending on language for multi language sites. But i woud like to make some sort of package that checks the current language culture and changes the node language node icon accordingly.

    Is this alot of work for someone whos just started digging into the api and how can i check the current language culture.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 09, 2010 @ 10:47
    Lee Kelleher
    3

    Hi Johan,

    The "magic" of the Icon Picker package is done by hooking up to the BaseTree.BeforeNodeRender event ... then checking the properties to see which icon to display.

    Here's a quick-n-dirty code snippet...

    namespace Bodenko.Umbraco.ApplicationEvents
    {
        using System;
        using System.Collections.Generic;
        using umbraco.BusinessLogic;
        using umbraco.cms.presentation.Trees;
        using umbraco.cms.businesslogic.web;
    
        public class CultureIcon : ApplicationBase
        {
            public CultureIcon()
            {
                BaseTree.BeforeNodeRender += new BaseTree.BeforeNodeRenderEventHandler(BaseTree_BeforeNodeRender);
            }
    
            void BaseTree_BeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e)
            {
                if (node.NodeType == "content")
                {
                    List<Domain> domains = Domain.GetDomains();
    
                    if (domains != null && domains.Count > 0)
                    {
                        foreach (Domain domain in domains)
                        {
                            if (domain.RootNodeId.ToString() == node.NodeID)
                            {
                                node.Icon = String.Concat("../path/to/images/", domain.Language.CultureAlias, ".gif");
                            }
                        }
                    }
                }
            }
        }
    }

    There are many ways to do this ... my thought would be to grab all the domains, loop through them, if the (current) node matches the root node id, then change the icon.  Performance wise, this would need a some work ... it's not good to grab all domains per each node render ... so maybe another check to find out which level the node is at? i.e. level = 1 is the base/root of your site?

    Let us know if you take this any further!

    Good luck, Lee.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Apr 09, 2010 @ 10:51
    Dirk De Grave
    1

    If you need to change a node's icon, consider looking into the BeforeNodeRender/AfterNodeRender event to change the node's icon based on the domain name/language culture assigned to the node.

    Great examply by Richard on how to subscribe to the event (he's adding a menu item to the node, whereas you should be changing the node's icon)

    Database table umbracoDomains hold the assigned domain names together with the culture and top node associated with it (and should get you enough info to change the icon)

     

    Hope this helps.

    Regards,

    /Dirk

  • Johan Möller 83 posts 137 karma points
    Apr 09, 2010 @ 12:50
    Johan Möller
    0

    Nice, Thanks for the quick help both of you :) Will post something when ive gotten a bit further with it.

Please Sign in or register to post replies

Write your reply to:

Draft