내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

how can I access a javascript variable in my HTL attribute

Avatar

Level 5
<sly data-sly-test=${isTrue}>
                <input type="radio" id="north-america" name="regions" value="north-america" class="destaco-input-radio">
                <label for="north-america">${"America" @ i18n, context='html'}</label>
</sly>
<script>
    var isTrue= true;
</script>
 
 
 
I am confused about how to use the "isTrue" variable inside my data-sly-test statement so that I can execute this piece of code
Thank you
 
 
I have to use this variable for both "true" and "false" statements
Please help me find out how to do it .
Thank you
1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Community Advisor

Hi,

You cannot use client side javascript variables value for server side execution.

You can always execute the code and based on javascript condition show/hide or do business logic on client side.

Arun Patidar

AEM LinksLinkedIn

원본 게시물의 솔루션 보기

3 답변 개

Avatar

Level 3

Please find similar query posted @ https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/pass-value-from-js-to-sly-... 

Please see if this helps.

 

Thanks

Anika

Avatar

정확한 답변 작성자:
Community Advisor

Hi,

You cannot use client side javascript variables value for server side execution.

You can always execute the code and based on javascript condition show/hide or do business logic on client side.

Arun Patidar

AEM LinksLinkedIn

Avatar

Employee Advisor

As mentioned by Arun, you can not use clientSide variables to render server side scripts.

 

In this case, you render your HTML and use javascript to show/hide block based on js Variable value.

<div class="showInput">
    <input type="radio" id="north-america" name="regions" value="north-america" class="destaco-input-radio">
    <label for="north-america">${"America" @ i18n, context='html'}</label>
</div>

# Hide showInput div block on page load
<style type="text/css">
    .showInput {
        display: none;
    }
</style>

<script>
    if(isTrue) {
        // Display showInput div block if JS object is true
    }
</script>