Expand my Community achievements bar.

SOLVED

What is the best way to add JSON-LD schema to pages that has a specific component

Avatar

Level 2

Hello! I am new to AEM, and I need to figure out how to add schema structured data (in JSON-LD format) to all pages that contain one of our custom components.

 

I know similar questions have been asked before, but the answers weren't very detailed and a bit unclear. I'd like to know about the different approaches, and which one would be the best/most efficient. 

 

Also it's important to note that we already have a lot of existing pages with this component, so I'm hoping for a solution that'll apply to those pages as well without having to do any re-authoring.  

 

I would also appreciate any links to resources that may be helpful. Thanks!

Edit: One other thing I am confused about, is it incorrect to add the json-ld schema data to the component itself? This seems like it would be a straightforward solution, but no one seems to recommend it. 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @IshaJa 
You can this logic to page component's head section

e.g

<sly data-sly-use.scriptPojo="${'com.myproj.core.models.GenerateApplicationJson'}">
		<script type="application/ld+json">
			${scriptPojo.getJson @ context='styleScript'}
		</script>
	</sly>

 

 



Arun Patidar

View solution in original post

4 Replies

Avatar

Level 2

Hi @arunpatidar,

 

Thanks for responding, but my main question was how to add the JSON-LD to pages that contain a specific component. We have hundreds of pages that may contain this component, so manually adding it in through a custom component isn't an ideal option.

Avatar

Correct answer by
Community Advisor

Hi @IshaJa 
You can this logic to page component's head section

e.g

<sly data-sly-use.scriptPojo="${'com.myproj.core.models.GenerateApplicationJson'}">
		<script type="application/ld+json">
			${scriptPojo.getJson @ context='styleScript'}
		</script>
	</sly>

 

 



Arun Patidar

Avatar

Administrator

@IshaJa Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni