<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Liferay 7.2 - How to set portlets to div programmatically</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=115087814" />
  <subtitle>Liferay 7.2 - How to set portlets to div programmatically</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=115087814</id>
  <updated>2026-04-03T19:12:52Z</updated>
  <dc:date>2026-04-03T19:12:52Z</dc:date>
  <entry>
    <title>RE: Liferay 7.2 - How to set portlets to div programmatically</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=115110907" />
    <author>
      <name>Fabio Carvalho</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=115110907</id>
    <updated>2019-09-06T11:32:00Z</updated>
    <published>2019-09-06T11:32:00Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi David and Olaf,&lt;br&gt;&lt;br&gt;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:&lt;br&gt;&lt;pre&gt;&lt;code&gt; {
&amp;amp;nbsp; &amp;amp;nbsp; "name": "Home",
&amp;amp;nbsp; &amp;amp;nbsp; "url": "home",
&amp;amp;nbsp; &amp;amp;nbsp; "layout": "my_custom_template",
&amp;amp;nbsp; &amp;amp;nbsp; "portlets": [
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; {
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; "column": "column-1",
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; "portlet": "com_liferay_portal_search_web_search_bar_portlet_SearchBarPortlet"
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; },
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; {
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; "column": "column-2",
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; "portlet": "com_liferay_portal_search_web_search_bar_portlet_SearchBarPortlet"
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; }
&amp;amp;nbsp; &amp;amp;nbsp; ]
}&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;I ended up with something like this:&lt;br&gt;&lt;pre&gt;&lt;code&gt;LayoutTypePortlet type = (LayoutTypePortlet) layout.getLayoutType();
type.addPortletId(theme.getUserId(), myPortletId, myColumnId, -1, false);&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;It is producing what I want. Is there any consequence of doing things like this?&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Fabio Carvalho</dc:creator>
    <dc:date>2019-09-06T11:32:00Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.2 - How to set portlets to div programmatically</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=115095980" />
    <author>
      <name>Olaf Kock</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=115095980</id>
    <updated>2019-09-05T07:58:48Z</updated>
    <published>2019-09-05T07:58:48Z</published>
    <summary type="html">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&amp;#39;t worry about in an environment like Liferay. Rather concentrate on solving business problems than infrastructure. &lt;br /&gt;There&amp;#39;s a small fraction of problems where this might be feasible, but most of the questions (&amp;#34;how do I do X (because I&amp;#39;ve been asked to Y)&amp;#34;) end up not justifying ignoring the existing infrastructure.&lt;br /&gt;One more argument: You might solve the problem now, but you&amp;#39;ll have to maintain it in future upgrades.</summary>
    <dc:creator>Olaf Kock</dc:creator>
    <dc:date>2019-09-05T07:58:48Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.2 - How to set portlets to div programmatically</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=115092683" />
    <author>
      <name>David H Nebinger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=115092683</id>
    <updated>2019-09-05T01:09:25Z</updated>
    <published>2019-09-05T01:09:25Z</published>
    <summary type="html">Normally you would just embed the portlet right in the layout template itself. You wouldn&amp;#39;t want to be dynamically trying to add/remove portlets in a layout template during page aggregation time.</summary>
    <dc:creator>David H Nebinger</dc:creator>
    <dc:date>2019-09-05T01:09:25Z</dc:date>
  </entry>
  <entry>
    <title>Liferay 7.2 - How to set portlets to div programmatically</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=115087813" />
    <author>
      <name>Fabio Carvalho</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=115087813</id>
    <updated>2019-09-04T16:26:40Z</updated>
    <published>2019-09-04T16:26:40Z</published>
    <summary type="html">Hi,&lt;br /&gt;&lt;br /&gt;I am using a custom template for my layout. My custom_template.tpl has a &amp;lt;div id=&amp;#34;something&amp;#34; /&amp;gt;. My question is: if I having the div ID and portlet ID, how do I programmatically add a portlet to this div?</summary>
    <dc:creator>Fabio Carvalho</dc:creator>
    <dc:date>2019-09-04T16:26:40Z</dc:date>
  </entry>
</feed>
