Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Macro: is ancestor to current document? View modes: 
User avatar
Member
Member
_charleswesley - 8/23/2013 4:16:26 PM
   
Macro: is ancestor to current document?
I've been wrapping my head around the hierarchical transformation as outlined here and I have been enjoying the power and flexibility this approach has.

What I have not figured out, however, is how to check to see if an item is an ancestor to the current page.

Example:

- root
---- Primary Page 1
-------- Secondary Page 1
------------ Tertiary Page 1
---- Primary Page 2
-------- Secondary Page 2
------------ Tertiary Page 2

What I'd like to do is apply a CSS class in the transformation that processes the Primary Page if the current page is below it in the hierarchy.

So in this case if the current page was Tertiary Page 1, Primary Page 1 would need the class.

Is there a simple macro if/then statement I can use to determine that?

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 8/24/2013 3:27:13 AM
   
RE:Macro: is ancestor to current document?
Hi,

Thank you for your message.

Unfortunately there is not an easy macro for this. You would need to create a custom macro http://devnet.kentico.com/docs/devguide/index.html?registering_cutom_macro_methods.htm

However Im not very sure what would the logic of this macro be.

Kind regards,
Richard Sustek

User avatar
Member
Member
_charleswesley - 8/26/2013 12:56:15 PM
   
RE:Macro: is ancestor to current document?
This is a good opportunity for me to learn more about custom macros even it ultimately doesn't solve my need.

I have a client-side solution in mind I'll try as well -- thanks for the link!

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 8/27/2013 12:25:12 AM
   
RE:Macro: is ancestor to current document?
There are some document level values and CMSContext level values you could use. For instance to get the document being procesed use

Eval("NodeID")
Eval("NodeParentID")

If using the CMSContext.CurrentDocument you can access the CurrentDocument.ParentNodeID property. You could then compare the document being rendered with the parent.

User avatar
Member
Member
_charleswesley - 8/27/2013 12:40:31 PM
   
RE:Macro: is ancestor to current document?
That seems like it would work for a two-deep hierarchy, but what if the CMSContext.CurrentDocument was three or more levels down the tree from the root level? Wouldn't the NodeParentId just be the node above?

I was thinking about something like the code below but I'm stuck on the second condition.

For whatever reason I can't seem to split the string into an array and then determine the length of the array:

{% if (CurrentDocument.NodeAliasPath.StartsWith(NodeAliasPath) && NodeAliasPath.Split("/").Length == 1) { return "class='selected'" } else { return " "} %}


I'm not sure why I can't return the length of the array?

But as for solving my problem, my assumption is if the node alias path is shared and there is only one slash, then it's the root node...

User avatar
Member
Member
lwhittemore-emh - 9/17/2013 11:00:49 AM
   
RE:Macro: is ancestor to current document?
If you figure it out please share. I am trying to do the same thing.