Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Adding dynamic meta tag to Page

Avatar

Level 5

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. 

Tessa_learner1_0-1654845246684.png

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>

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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/conte... 

 



Arun Patidar

View solution in original post

4 Replies

Avatar

Level 5

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. 

Avatar

Level 4

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

Avatar

Correct answer by
Community Advisor

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/conte... 

 



Arun Patidar