Although you may want to write a custom transformation function and use caching (since to do this you'll have to do a sub-query for each item of the transformation, which depending on the items can cause delays so caching the results will be vital for fast performance), the code is as below.
CMS.DocumentEngine.DocumentHelper.GetDocuments("CMS.MenuItem").Where("NodeParentID = " + Eval("NodeID") + " and MenuItemGroup like '%" + CMS.DataEngine.SqlHelper.EscapeQuotes(ItemGroupContainsName) + "%'").Count > 0
This checks only the immediate children. If you want to check for any child at any level, just use
CMS.DocumentEngine.DocumentHelper.GetDocuments("CMS.MenuItem").Where("NodeAliasPath like '" + Eval("NodeAliasPath") + "/%' and MenuItemGroup like '%" + CMS.DataEngine.SqlHelper.EscapeQuotes(ItemGroupContainsName) + "%'").Count > 0
Below is the full app_code class that will add this method with proper caching:
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.Helpers;
using CMS.Membership;
using CMS.SiteProvider;
using System.Linq;
namespace CMS.Controls
{
/// <summary>
/// Extends the CMSTransformation partial class.
/// </summary>
public partial class CMSTransformation
{
/// <summary>
/// Trims text values to the specified length.
/// </summary>
/// <param name="txtValue">Original text to be trimmed</param>
/// <param name="leftChars">Number of characters to be returned</param>
public bool HasChildrenOfItemGroup(object DocumentIDobj, string ItemGroupContainsName)
{
int DocID = ValidationHelper.GetInteger(DocumentIDobj, -1);
if(DocID < 0) {
return false;
// Possibly also report error to event log
}
return CacheHelper.Cache<bool>(cs => HasChildrenOfItemGroupHelper(cs, DocID, ItemGroupContainsName), new CacheSettings(10, "hasChildrenOfItemGroup|DocID:" + DocID.ToString() + "|ContainName:" + ItemGroupContainsName));
}
private bool HasChildrenOfItemGroupHelper(CacheSettings cs, int DocumentID, string ItemGroupContainsName)
{
var theDocument = DocumentHelper.GetDocument(DocumentID, new TreeProvider(MembershipContext.AuthenticatedUser));
bool result = DocumentHelper.GetDocuments("CMS.MenuItem").Where("NodeParentID = " + theDocument.NodeID + " and MenuItemGroup like '%" + SqlHelper.EscapeQuotes(ItemGroupContainsName) + "%'").Count > 0;
//bool result = theDocument.Children.Where(x => x.GetStringValue("MenuItemGroup", "").ToLower().Contains(ItemGroupContainsName.ToLower())).Count() > 1;
// Checks whether the data should be cached (based on the CacheSettings)
if (cs.Cached)
{
// Sets the cache dependency to remove this cache for any changes on the child nodes of this document.
cs.CacheDependency = CacheHelper.GetCacheDependency("node|"+SiteContext.CurrentSiteName+"|"+theDocument.NodeAliasPath+"|childnodes");
}
return result;
}
}
}
The transformation method call will then be
<%# If(HasChildrenOfItemGroup(Eval("DocumentID"), "top"), "menu__item--withsub", "") %>
Took a bit to get this going and tested, so please mark as answered if helped!