Expand my Community achievements bar.

SOLVED

Pass Property Value to JavaScript Function

Avatar

Level 4

Hello,

I'm trying to pass the value from cq:dialog property to a JavaScript function but the compiler is erroring out on the '$'.  If I wrap the property in quotes, it's treated like a string.  How can I get around this? Using AEM 6.4

<div><sly data-sly-use.logic="${'clientlibs/js/logic.js' @ width=${properties.width}, height=${properties.height}, seperator=','}">

   ${logic.getFrame}</sly>

</div>

Same thing with a script tag; when written out to the Publisher the value is null

    <script>

        myFunction(${properties.name}) {

            // whatever

        });

    </script>

1 Accepted Solution

Avatar

Correct answer by
Level 8

Try below code :

var name = '${properties.name @ context="scriptString"}';

<script>

        myFunction(name) {

            // whatever

        });

    </script>

<div><sly data-sly-use.logic="${'clientlibs/js/logic.js' @ width=properties.width, height=properties.height, seperator=','}">

   ${logic.getFrame}</sly>

</div>

View solution in original post

1 Reply

Avatar

Correct answer by
Level 8

Try below code :

var name = '${properties.name @ context="scriptString"}';

<script>

        myFunction(name) {

            // whatever

        });

    </script>

<div><sly data-sly-use.logic="${'clientlibs/js/logic.js' @ width=properties.width, height=properties.height, seperator=','}">

   ${logic.getFrame}</sly>

</div>