Expand my Community achievements bar.

SOLVED

Sightly - Changes on node level

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Employee

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();

    }

 

}

View solution in original post

6 Replies

Avatar

Employee Advisor

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

Avatar

Correct answer by
Employee

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();

    }

 

}

Avatar

Level 4

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

Avatar

Employee

+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.

Avatar

Employee Advisor

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

Avatar

Level 4

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