Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Insert JS only in search-result page of the site

Avatar

Level 3

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!

1 Accepted Solution

Avatar

Correct answer by
Level 10

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.htm...

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

 

 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

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.htm...

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