tl;dr: How can I load custom fields for current data item of the repeater inside Text/XML tranformation in hierarcical viewer? By default it's not loaded and I have to use WithAllData call on ALL CMSContext.Documents for each menu item - which is very inefficient. Looking for better solution.
I'm building a menu using "Text/XML transformation". The reason for that is that I need to have a complex logic (if/else), and the only way to get this working using ASCX transformations as far as I can see was a custom backend logic which returns HTML markup - which I'm not a fan of. For example, as an item template, I need this:
<li><a>MENU TITLE</a>
when current menu item has no children, and this:
<li><span>MENU TITLE</span>
<ul>
<li><a>MENU TITLE2</a></li>
when it does have children. Note that <li>
is not closed (I'm using separator transformations for that - as per Kentico's "grand menu" example I found somewhere in the internet). That prevents me using
<li runat=server visible="<%# some-logic %>
trick with ASCX transformation. So I decided to go with "Text/XML" one. Here is how item transformation looks like:
{%
temp = List(Documents[NodeAliasPath]);
if (GetCountChildrenMenuNodes(NodeGUID)>0) {
temp.ApplyTransformation("cms.menuitem.ItemWithChildren")
} else {
temp.ApplyTransformation("cms.menuitem.ItemWithoutChildren")
}
#%}
and here is the cms.menuitem.ItemWithChildren one (a bit simplified):
{%
menuTitleIfParent = Documents.WithAllData[NodeAliasPath].GetValue("MenuTitleIfParent");
#%}
<li class='parent'>
<span>{%DocumentName%}</span>
<ul>
<li><a>{%menuTitleIfParent%}</a></li>
Basically, the question (trouble) is that without WithAllData in Documents.WithAllData[NodeAliasPath]
expression, my custom field MenuTitleIfParent
is not loaded, and GetValue("MenuTitleIfParent")
returns nothing. Loading all data for all documents many-many times (while building the menu) seems very inefficient to me. How can I load custom field just for the current item of the repeater for Text/XML tranformation?