Expand my Community achievements bar.

SOLVED

How to move a node to a particular position programmatically?

Avatar

Level 4

Hi All,

I want to move a node above or below to a particular node in sightly handler. Similar to how we order a node in CRXDE manually. 

Ex:

jcr:Content

    Node1

    Node2

    Node0

Now, I want to move Node0 above Node1, in sightly handler.

Regards,

Vikram.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Vikram,

There is  com.day.cq.commons.jcr.JcrUtil API available through which you can reorder/move your nodes.There is setChildNodeOrder() method where you specify the new order for the children.

 

Hope this helps!

Nupur

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi Vikram,

There is  com.day.cq.commons.jcr.JcrUtil API available through which you can reorder/move your nodes.There is setChildNodeOrder() method where you specify the new order for the children.

 

Hope this helps!

Nupur

Avatar

Level 3

 

Session session = resourceResolver.adaptTo(Session.class);

session.move(srcpath,destpath);

session.save();