Forums de discussion

Link WebContent to another WebContent

Angelo ZERR, modifié il y a 10 années.

Link WebContent to another WebContent

New Member Publications: 10 Date d'inscription: 06/11/13 Publications récentes
Hi all,

I'm using Liferay liferay6.2.0-ce-ga1 and I need to link WebContent to another WebContent, for instance writing WebContentA like this:

Here a link to <a href="WebContentB">WebContentB</a>


My first requirement is to set WebContentA inside the "Web Content Display" Portlet and when you click on WebContentB link, it refreshes the portlet with the content of WebContentB.

To manage that, there are several problems :
  • the link URL to WebContentB is composed with the portalId (for Liferay URL and Friendly URL) which is dynamic (if you remove and add the portlet, this portletid changes). So it's not possible to set thef ull URL of WebContentB in the WebContentA.
  • that's why, the link URL to WebContentB must be dynamic, but a content of WebContent is not dynamic : it's not possible to use Freemarker syntax in the content of WebContent.


I have found a solution by managing the WebContent link with Javascript by using Javascript Liferay API. Now I can write this WebContent :

Here a link to <a href="#" onclick="Liferay.Journal.display(this, '13310');return false;">WebContentB</a>


where 13310 is the articleId of WebContentB. Liferay.Journal is a javascript function which looks like this :

AUI().use('event', 'node', function(A) {
	(function() {

		Liferay.Journal = {

			getPortlet : function(elt) {
				var nodeObject = A.one(elt);
				return nodeObject.ancestor('.portlet-boundary');
			},

			display : function(elt, articleId) {
				var portletNode = Liferay.Journal.getPortlet(elt);
				var portletId = portletNode.portletId;
				var renderURL = Liferay.PortletURL.createRenderURL();
				renderURL.setParameter("articleId", articleId);
				renderURL.setPortletId(portletId);
				renderURL.setPortletMode("view");
				renderURL.setWindowState("normal");
				//alert(renderURL.toString());
				window.location = renderURL.toString();
			}
		};
	})();
});


I'm improving this javascript to manage asset publisher too and manage too link WebContent to another WebContent which opens the WebContent on another "Web Content Display" Portlet which belongs to another page.

I think it should be very cool if Liferay provides this feature, because this link is not standard (I cannot type this link in the webcontent and it should be more user friendly to have an UI to select a webcontent to link.

Hope you will like this idea.

Regards Angelo
Angelo ZERR, modifié il y a 10 années.

RE: Link WebContent to another WebContent

New Member Publications: 10 Date d'inscription: 06/11/13 Publications récentes
Hi,

For your information, I have created the project https://github.com/angelozerr/liferay-link-to-webcontent which gives you the capability to write your link to WebContent like this :

<a data-liferay-articleid="13502 " href="#">link to WebContent2</a>


When you click on this link, it refreshes the portlet with the referenced WebContent by using Liferay Javascript API.

Hope you will like it.
Ethan Maddox, modifié il y a 9 années.

RE: Link WebContent to another WebContent

New Member Envoyer: 1 Date d'inscription: 17/05/14 Publications récentes
Ahh thanks Angelo. I was looking to do just this and what you suggested worked perfectly. Thanks!