Search code examples
sightly

How to remove a variable from request after use in Sightly?


I've a situation where I needed a request attribute to identify from which container component the child components are rendered. Based on which I am changing the behaviour of child component. However, I want to clean off the request attribute after the child components are rendered. How do I achieve this in sightly?


Solution

  • You can write a script (say clear.js) to clear request variable:

    /*
     * Clear request objects
     */
    
    "use strict";
    
    use([], function () {
        request.removeAttribute("variableName");
        request.removeAttribute("variableName");
    });
    

    Call this script from your sightly code:

    <sly data-sly-use="clear.js"> </sly>