Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Liferay 7.2 - How to set portlets to div programmatically
Hi,
I am using a custom template for my layout. My custom_template.tpl has a <div id="something" />. My question is: if I having the div ID and portlet ID, how do I programmatically add a portlet to this div?
I am using a custom template for my layout. My custom_template.tpl has a <div id="something" />. My question is: if I having the div ID and portlet ID, how do I programmatically add a portlet to this div?
Normally you would just embed the portlet right in the layout template itself. You wouldn't want to be dynamically trying to add/remove portlets in a layout template during page aggregation time.
Feels like a X-Y problem to me. What is the reason for trying this? This is the kind of infrastructural work that you shouldn't worry about in an environment like Liferay. Rather concentrate on solving business problems than infrastructure.
There's a small fraction of problems where this might be feasible, but most of the questions ("how do I do X (because I've been asked to Y)") end up not justifying ignoring the existing infrastructure.
One more argument: You might solve the problem now, but you'll have to maintain it in future upgrades.
There's a small fraction of problems where this might be feasible, but most of the questions ("how do I do X (because I've been asked to Y)") end up not justifying ignoring the existing infrastructure.
One more argument: You might solve the problem now, but you'll have to maintain it in future upgrades.
Hi David and Olaf,
I have a JSON file with an array of Layouts. Each Layout have a name, url, template and portlets IDs to add according to his template. Here is an example of an object of this array:
I ended up with something like this:
It is producing what I want. Is there any consequence of doing things like this?
I have a JSON file with an array of Layouts. Each Layout have a name, url, template and portlets IDs to add according to his template. Here is an example of an object of this array:
{
"name": "Home",
"url": "home",
"layout": "my_custom_template",
"portlets": [
{
"column": "column-1",
"portlet": "com_liferay_portal_search_web_search_bar_portlet_SearchBarPortlet"
},
{
"column": "column-2",
"portlet": "com_liferay_portal_search_web_search_bar_portlet_SearchBarPortlet"
}
]
}
I ended up with something like this:
LayoutTypePortlet type = (LayoutTypePortlet) layout.getLayoutType();
type.addPortletId(theme.getUserId(), myPortletId, myColumnId, -1, false);
It is producing what I want. Is there any consequence of doing things like this?
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™