Foren

Change HTML-Title for Facebook

Jan Bub, geändert vor 11 Jahren.

Change HTML-Title for Facebook

Junior Member Beiträge: 78 Beitrittsdatum: 02.03.11 Neueste Beiträge
Hey,

while playing with the facebook like button in my JSF Portlet I got a little problem. If I like an entity facebook get a special link which open the liferay page with the portlet. The portlet recognizes an id of the url and shows automatic the view with the entity details.
My problem is that Facebook will show always the title of the site which contains the portlet. How can i change the <title> tag?

I have seen, that e.g the Blogs Portlet can handle it .The page title is the name of the blog entry. Therefor facebook shows the right title for blog entries. Is there a smart way to make it like the Blogs Portlet.
thumbnail
Neil Griffin, geändert vor 11 Jahren.

RE: Change HTML-Title for Facebook

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
The value of the <title>...</title> element in the portal page HTML document is defined in the portal_normal.vm Velocity template in the theme.
Jan Bub, geändert vor 11 Jahren.

RE: Change HTML-Title for Facebook (Antwort)

Junior Member Beiträge: 78 Beitrittsdatum: 02.03.11 Neueste Beiträge
You are right, but changing the title from that point seems to be a little bit complicated.

But I hope I have found an easy solution by looking in the blogs portlet. PortalUtil have some methods to change the site title and description. So I use them if my portlet get the id to show the entity view.

For all who have the similar problem, here is my code:


...
	// if entityId from the URL (e.g. von FaceBook Like Link)
	if (requestMap.get("entityId") != null	&amp;&amp; !requestMap.get("entityId").equals("0")) {

			setCurrentEntityId(Long.parseLong(requestMap.get("entityId")));

			PortletRequest portletRequest = (PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
			HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);
			
			PortalUtil.setPageSubtitle(this.currentEntity.getBookTitle(), request);
			PortalUtil.setPageDescription(this.currentEntity.getDescription(),request);

			this.viewState = "showEntity";
		}
...


I couldn't test it yet because I need an online system to make it parseable for facebook. But my online test system today is needed for a presentation. I will let you know if it is not working unexpectly. But looking into the html source code on my local machine it seems to look fine.

[Addition] It is working.