Sightly - Changes on node level | Community
Skip to main content
Premkarthic-7WP
Level 4
October 16, 2015
Solved

Sightly - Changes on node level

  • October 16, 2015
  • 6 replies
  • 1947 views

Hi,

Is it possible to make some changes on node level like setting property using sightly(".html file") ?. In sightly doc (http://dev.day.com/content/docs/en/aem/6-0/develop/sightly.html) they mentioned like Java-backed Objects will be available. 

If so, how it should be done?.Or otherwise we should use java class or js ?

Please provide some snapshot of code for reference.

Requirement : Need to set some 'x' property on node while each time page get loads.

Thanks,

Karthi

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Feike_Visser1

Here an example of such a use-class..

public class NodeChange extends WCMUse {

 

@Override

    public void activate() throws Exception {

        ModifiableValueMap mvp = getResource().adaptTo(ModifiableValueMap.class);

        mvp.put("x", "yourValue");

        getResourceResolver().commit();

    }

 

}

6 replies

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

I don't think, that it's a good idea to make any direct changes on the repository when you render a page. Just think how this might work on the publish side, or when the page is delivered out of a cache, etc.

Jörg

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

Here an example of such a use-class..

public class NodeChange extends WCMUse {

 

@Override

    public void activate() throws Exception {

        ModifiableValueMap mvp = getResource().adaptTo(ModifiableValueMap.class);

        mvp.put("x", "yourValue");

        getResourceResolver().commit();

    }

 

}

Premkarthic-7WP
Level 4
October 16, 2015

Jörg Hoh wrote...

I don't think, that it's a good idea to make any direct changes on the repository when you render a page. Just think how this might work on the publish side, or when the page is delivered out of a cache, etc.

Jörg

 

Jorg,

Thanks for your input. I will set the property only on author mode (not on publish) for doing certain manipulation and that too not on every time, will do only for certain events.

Thanks,

Karthi

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

+1, if you use the dispatcher then your page may be loaded only once for a certain amount of time.

But at least you have an example of the code.

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

Hi Karthi,

I wouldn't do that; if the rendering of a page shouldn't have any side effects. At least that's the idea when you follow the REST paradigm regarding the HTTP verb "GET".

Jörg

Premkarthic-7WP
Level 4
October 16, 2015

Jorg,

Thanks for your valuable input.

You are suggesting me to use POST instead of GET if a have any requirement like that rite? This work well fine for form submission.

Can i do the same for dialog submission?

What is the best way to do,

If i need to create certain nodes and to set some properties after submitting the dialog. Please advice.

It will be more helpful if you provide some reference urls for understanding the rest to the best. I am quite new to this technology.

 

Thanks in advance.

 Thanks,

Karthi