How to Integrate one script to all pages of metadata | Community
Skip to main content
Level 2
Mar 18, 2021 12:49 PM UTC
Solved

How to Integrate one script to all pages of metadata

 

There will be one script that we need to add on all the pages in metadata

So can you please help me  where we need to add this script so that it will start loading on all the templates
 
 
 
 
 
Thanks in advance
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Asutosh_Jena_
Asutosh_Jena_Accepted solution
New Participant
Mar 18, 2021 4:38 PM UTC

Hi @mounikasri 

If you are trying to include some metadata HTL script across all the pages for any website, please overlay your page template (head.html) file where all the matadata for a page are defined.

Now you can create another HTL file with the required HTL script and include the file in the path at the desired location, preferrably after the metatags.


<meta charset="UTF-8">
<title>${page.title}${page.brandSlug ? ' | ' : ''}${page.brandSlug}</title>
<meta data-sly-test.keywords="${page.keywords}" name="keywords" content="${keywords}"/>
<meta data-sly-test.description="${properties['jcr:description']}" name="description" content="${description}"/>
<meta data-sly-test.templateName="${page.templateName}" name="template" content="${templateName}"/>
<meta name="viewport" content="width=device-width, initial-scale=1">

<-- Your file/custom meta script should go here -->


This will ensure all the pages that are created using this template which uses this page component will have the script loaded.

 

Please refer the core component head.html file below:
https://github.com/adobe/aem-core-wcm-components/blob/master/content/src/content/jcr_root/apps/core/wcm/components/page/v2/page/head.html

 

Hope this helps!

Thanks!

4 replies

Asutosh_Jena_
Asutosh_Jena_Accepted solution
New Participant
Mar 18, 2021 4:38 PM UTC

Hi @mounikasri 

If you are trying to include some metadata HTL script across all the pages for any website, please overlay your page template (head.html) file where all the matadata for a page are defined.

Now you can create another HTL file with the required HTL script and include the file in the path at the desired location, preferrably after the metatags.


<meta charset="UTF-8">
<title>${page.title}${page.brandSlug ? ' | ' : ''}${page.brandSlug}</title>
<meta data-sly-test.keywords="${page.keywords}" name="keywords" content="${keywords}"/>
<meta data-sly-test.description="${properties['jcr:description']}" name="description" content="${description}"/>
<meta data-sly-test.templateName="${page.templateName}" name="template" content="${templateName}"/>
<meta name="viewport" content="width=device-width, initial-scale=1">

<-- Your file/custom meta script should go here -->


This will ensure all the pages that are created using this template which uses this page component will have the script loaded.

 

Please refer the core component head.html file below:
https://github.com/adobe/aem-core-wcm-components/blob/master/content/src/content/jcr_root/apps/core/wcm/components/page/v2/page/head.html

 

Hope this helps!

Thanks!

Translate
Rohit_Utreja
New Participant
Mar 18, 2021 2:02 PM UTC

@mounikasri 

 

If you are using a static template, then create a base template. All templates should inherit this base template so this way you will have one location which will be common for all templates.

 

Now, after di=oing above, if you want to add a new script, you can do it in the base template and inheritance will help you to add it on all pages.

Translate
Employee
Mar 18, 2021 1:48 PM UTC
Sorry - what pages do you mean exactly? Also, do you mean JavaScript or HTL/JSP scripts?
Translate
Nikhil-Kumar
New Participant
Mar 18, 2021 1:31 PM UTC

@mounikasri - You can add it in the Base Page template or the template by using which you have created the pages. (In their HTML /JSP files).


Thanks,
Nikhil Kumar

Translate