Adding dynamic meta tag to Page | Community
Skip to main content
Level 4
June 10, 2022
Solved

Adding dynamic meta tag to Page

  • June 10, 2022
  • 1 reply
  • 1617 views

Hi all, 

I am trying to add the below custom meta tag to page. How to render these multifield values to page. I don't have a clear idea how to do. 

Sling model:

package com.pocdemosite.core.models;
import com.adobe.cq.sightly.WCMUsePojo;

import java.util.ArrayList;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;

public class MetaTag extends WCMUsePojo {
private ArrayList<String> metaData =new ArrayList<>();
@Override
public void activate() throws RepositoryException {
Node currentNode = getResource().adaptTo(Node.class);
if(currentNode.hasNode("metaTag")){
Node metaDataNode = currentNode.getNode("metaTag");
NodeIterator ni = metaDataNode.getNodes();
while (ni.hasNext()) {
Node child = (Node)ni.nextNode();
metaData.add(child.getProperty("metatag").getString());
}
}

}


}

 

HTL 

<sly data-sly-use.metaModel="com.pocdemosite.core.models.MetaTag" data-sly-unwrap></sly>

<div data-sly-list.tagName="${metaModel.metaData}" data-sly-unwrap>
<meta name="${tagName}" content="${metaModel.metaData[tagName]}" />
</div>

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

You can retrieve and use in head.html and create meta tag keywords that use Tag page property e.g.

https://github.com/adobe/aem-core-wcm-components/blob/63fbf78be4f2364ad7c3a2766c502b7767c8270c/content/src/content/jcr_root/apps/core/wcm/components/page/v3/page/head.html#L21 

 

1 reply

arunpatidar
Community Advisor
Community Advisor
June 10, 2022
Level 4
June 10, 2022

Hi @arunpatidar Thanks. But meta tags should be added on the page source right. If I do the method it will retrive the values to the page not append to page resource. 

June 10, 2022

You can use JS to identify target elements and update HTML using meta tags.