Combination View Flat View Tree View
Threads [ Previous | Next ]
Jan Bub
Change HTML-Title for Facebook
January 18, 2013 6:53 AM
Answer

Jan Bub

Rank: Junior Member

Posts: 78

Join Date: March 2, 2011

Recent Posts

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.
Neil Griffin
RE: Change HTML-Title for Facebook
January 14, 2013 9:06 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1973

Join Date: July 26, 2005

Recent Posts

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
RE: Change HTML-Title for Facebook
January 18, 2013 1:43 PM
Answer

Jan Bub

Rank: Junior Member

Posts: 78

Join Date: March 2, 2011

Recent Posts

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:

 1
 2...
 3    // if entityId from the URL (e.g. von FaceBook Like Link)
 4    if (requestMap.get("entityId") != null    && !requestMap.get("entityId").equals("0")) {
 5
 6            setCurrentEntityId(Long.parseLong(requestMap.get("entityId")));
 7
 8            PortletRequest portletRequest = (PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
 9            HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);
10            
11            PortalUtil.setPageSubtitle(this.currentEntity.getBookTitle(), request);
12            PortalUtil.setPageDescription(this.currentEntity.getDescription(),request);
13
14            this.viewState = "showEntity";
15        }
16...


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.

It is working.