Insert JS only in search-result page of the site | Adobe Higher Education
Skip to main content
Level 3
April 26, 2022
해결됨

Insert JS only in search-result page of the site

  • April 26, 2022
  • 2 답변들
  • 798 조회

Hi All,

We are integrating a page-specific adsense script in the head.html based on currentPage.name .So could anyone please recommend any other ways to dynamically integrate the javascript only in search page of the site.

 

Thanks in Advance!

이 주제는 답변이 닫혔습니다.
최고의 답변: Anish-Sinha

hi @keerthi97 ,

You can create a client library with the scripts and include that in the search results component. In that case you don't have to load it in the head.html and will be just loaded on the search results page where that component will be used. 

If there is no search result component that is used on the results page, you can put a condition in the html using data-sly-test attribute, and then load the js. In this case also, it will load only in that specific page.

some useful links-

https://experienceleague.adobe.com/docs/experience-manager-65/developing/introduction/clientlibs.html?lang=en#

https://experienceleague.adobe.com/docs/experience-manager-htl/using/htl/block-statements.html?lang=en#test

 

 

2 답변

Anish-Sinha
Adobe Employee
Adobe Employee
April 27, 2022

hi @keerthi97 ,

You can create a client library with the scripts and include that in the search results component. In that case you don't have to load it in the head.html and will be just loaded on the search results page where that component will be used. 

If there is no search result component that is used on the results page, you can put a condition in the html using data-sly-test attribute, and then load the js. In this case also, it will load only in that specific page.

some useful links-

https://experienceleague.adobe.com/docs/experience-manager-65/developing/introduction/clientlibs.html?lang=en#

https://experienceleague.adobe.com/docs/experience-manager-htl/using/htl/block-statements.html?lang=en#test

 

 

November 17, 2023

Your questions show that you are actively engaging with the material. It encourages further exploration of the topic and helps other readers gain a deeper understanding.

source Tenor Life