CSS List Menu - how to get current item (NodeID) in the macro in WHERE Condition

Canelle Michel asked on January 29, 2019 16:06

Hi,

I'm trying to implement sort of a secondary navigation, using a CSS List Menu webpart that I placed in my root page template.

I implemented a custom macro (let's call it SecondaryNavigation(int evalutedNodeID, int currentNodeID). That macro contains the logic restricting what items should or should not appear in the secondary menu, based on two parameters: the current page and the evaluated page NodeIDs. That macro returns the evaluated apge NodeID if that page should appear in the menu, else -1.

(I did try to return true or false before, but didn't manage to get it to fit into the WHERE condition without it breaking/getting all red/yellow/full of errors).

In the CSS List Menu webpart, I would like to have the following WHERE condition: NodeID = {%CustomNamespace.SecondaryNavigation(<DataItem>.NodeID, CurrentDocument.NodeID)%}

However, I'm not sure on how to to get that NodeID value of the item currently being evaluted by the WHERE expression in the SQL Query(and I'm not even sure that's possible)

Does anyone has any idea on the name of that sweet parameter? (or any counter argument?)

Many thanks!

Canelle

Correct Answer

Trevor Fayas answered on January 29, 2019 19:28

Hey Canelle,

If i'm getting this correctly, you want to create a WHERE condition that shows all the Pages that should show as a secondary navigation for your current page.

In which case, you should do something like

NodeID IN ({% Your Macro Here that returns all the applicable NodeIDs, comma seperated, or 0 if none %})

so it will render out

NodeID in (5,234,30,47)

etc.

Does that make sense?

1 votesVote for this answer Unmark Correct answer

Recent Answers


Zach Perry answered on January 29, 2019 18:22

I'm the best at SQL, but I don't think you can use the Where condition this way.

I would either move your logic from your macro into sql (probably the best for performance) or assuming the CSSList web part (been a while since i used it) has a transformation, you would run your macro for each item that is returned and in the transformation decide to display that current item or not.

0 votesVote for this answer Mark as a Correct answer

Canelle Michel answered on January 30, 2019 15:03

@Zach, indeed, you cannot use the WHERE condition that way.

I went with Trevor solution (thanks!), implemented the function that returns the proper nodes in a list.
Changed the CSS List Menu part to a Repeater for styling reasons, and voilà! All the proper items are displayed.

I still do get a strange result though. I wanted to add some style for selected items, and therefore I'm using two transformations :

  • Transformation: SecondaryMenuLink
  • Selected item transformation: SecondaryMenuLinkHighlighted

The issue is that when doing so, only the selected item does actually gets retrieved & displayed (which is kind of cumbersome). When I remove that selected transformation, all items get displayed.

The code of the transformation is quite simple:

<li class="Highlighted">
   <a href="{%NodeAliasPath%}">{%DocumentName%}</a>
</li>

I searched for the repeater documentation, but didn't read anywhere that it wasn't possible to have two transformations for a same repeater.

Since my code is kinda basic, I'm considering using JavaScript to add the proper class tag, but it would have been nicer to have been able to that in the web part configuration.

Any ideas on what breaks here?

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on January 30, 2019 15:18

The Selected Item Transformation on a repeater is meant to be the "Detail" of a Listing display (ex Transformation = Blog List, Selected Item Transformation = Blog detail when you click on one), this is because you can use the same Page template for both listing and details with this feature.

If you are using a repeater, then what you should try to do is just add in the "Highlighted" class logic yourself.

For example, use this as your transformation, no selected item one.

<li class="{% NodeAliasPath == CurrentDocument.NodeAliasPath ? "Highlighted" : "" @%}">
   <a href="{%NodeAliasPath%}">{%DocumentName%}</a>
</li>
0 votesVote for this answer Mark as a Correct answer

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