Forums de discussion
Adding custom meta tags from custom portlet
Tomi Savolainen, modifié il y a 14 années.
Adding custom meta tags from custom portlet
New Member Publications: 6 Date d'inscription: 13/10/08 Publications récentes
Hi,
I would like to know is there a way to add html meta-tags in Liferay. I would like to be able to add meta-data in a page that would read the data from a portlet and write it in the head of a html-page. I know only that there is a method in PortalUtil that can
Thanks in advance
I would like to know is there a way to add html meta-tags in Liferay. I would like to be able to add meta-data in a page that would read the data from a portlet and write it in the head of a html-page. I know only that there is a method in PortalUtil that can
Thanks in advance
Tomi Savolainen, modifié il y a 14 années.
RE: Adding custom meta tags from custom portlet
New Member Publications: 6 Date d'inscription: 13/10/08 Publications récentes
addProperty method in RenderResponse should probably do the trick but I can't get it to create an element that would not be null. Has anybody managed to do this?
Tomi Savolainen, modifié il y a 14 années.
RE: Adding custom meta tags from custom portlet
New Member Publications: 6 Date d'inscription: 13/10/08 Publications récentes
I guess this is solved
httpRequest.setAttribute(MimeResponse.MARKUP_HEAD_ELEMENT, Arraylist.asList("bar", "foo");
Orin Fink, modifié il y a 7 années.
RE: Adding custom meta tags from custom portlet
Junior Member Publications: 65 Date d'inscription: 25/03/10 Publications récentes
Inside a Spring MVC based portlet I was successful in adding the meta tags in the following manner. This example was built specifically for adding the Open Graph Meta tags that I wanted. Your use may vary...
@RequestMapping(params = "action=detail-view")
public String detailView(RenderRequest request, RenderResponse response, Model model){
buildOpenGraphMetaTag("og:title", "The Rock", response);
buildOpenGraphMetaTag("og:url", "http://www.imdb.com/title/tt0117500/", response);
buildOpenGraphMetaTag("og:image", "http://ia.media-imdb.com/images/rock.jpg", response);
return "view";
}
private void buildOpenGraphMetaTag(String property, String content, RenderResponse response){
Document doc = null;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Element element = doc.createElement( "meta");
element.setAttribute( "content", content );
element.setAttribute( "property", property );
response.addProperty( MimeResponse.MARKUP_HEAD_ELEMENT, element );
}