Kentico transformations for node name from node guid

Matthew Butler asked on June 28, 2022 18:06

I was previously storing the Node ID in the DB, and using the uni selector to select a given node.

Then for the user interface I used "#transform: cms.node.nodename" against the node id.

I then realised I can't used the node IDs with CI so I switched to Guids, but now the transforms don't work.

What is the correct approach?

Thanks

Correct Answer

Matthew Butler answered on June 29, 2022 18:08

I ended up creating a module

protected override void OnInit()
{
    base.OnInit();
    UniGridTransformations.Global.RegisterTransformation("#nodeName", NodeName);
}

private static object NodeName(object parameter)
{
    return DocumentHelper.GetDocuments()
                .WhereEquals(nameof(TreeNode.NodeGUID), ValidationHelper.GetGuid(parameter, Guid.Empty))
                .Columns("NodeName")
                .TopN(1)
                .FirstOrDefault()?.NodeName;
}
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.