Pass Property Value to JavaScript Function | Community
Skip to main content
MktgCloudUser
New Participant
October 10, 2018
Solved

Pass Property Value to JavaScript Function

  • October 10, 2018
  • 1 reply
  • 3354 views

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>

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 raj_mandalapu

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>

1 reply

raj_mandalapu
raj_mandalapuAccepted solution
New Participant
October 10, 2018

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>