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

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

Mark Solution

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

해결됨

How to include script directly in sightly html component

Avatar

Level 4

Hi Team,

How can we include a script directly in sightly component

Trying to include a script for datalayer directly in a component.

Regards

Ankur

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Level 10
5 답변 개

Avatar

Employee

<sly data-sly-include="yourscript.html" />

This is how you include scripts.

Avatar

Administrator

Hi

Adding to what Feike said,

Please have a look at this community article covering many example for HTL (formerly know as Sightly).

Link:-http://blogs.adobe.com/experiencedelivers/experience-management/htl-intro-part-1/

~kautuk



Kautuk Sahni

Avatar

정확한 답변 작성자:
Level 10

Avatar

Level 4

Feike Visser wrote...

<sly data-sly-include="yourscript.html" />

This is how you include scripts.

 


So can we include following script directly in "yourscript.html " directly and use as u specified above-

 <script>  
 
    var digitalData = $('#digitalData').val();
    var date = new Date();
    var clientHourOfDay = date.getHours();
    var pageVisitJson = JSON.parse('${datalayer.pageVisitAsString}');
    var systemHourOfDay = pageVisitJson['hourOfDay'];
    var diffHourOfDay = clientHourOfDay - systemHourOfDay;
    var days = ['Sunday','Monday','Tu','W','Th','Fry','Satuay'];
    var isWeekend = "false";
    if (diffHourOfDay >= -2 && diffHourOfDay <= 2) {
        digitalData.visit.hourOfDay = clientHourOfDay;
        digitalData.visit.dayOfWeek = days[date.getDay()];
        if(date.getDay()===6 || date.getDay()===0){isWeekend="true";}
        digitalData.visit.isWeekend = isWeekend;
    }    

 
    

  </script>

Avatar

Level 2

Yes. Although you will probably need to include the "@context=" where appropriate since you are populating a JS string. You will need to chose the appropriate context scriptstring, unsafe, etc.. that matches what you populating.