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.
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?
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.
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)
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.
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...
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.
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
Nice, Thanks for the quick help both of you :) Will post something when ive gotten a bit further with it.
is working on a reply...