Foren

Getting layout column width programatically

Martin Pasko, geändert vor 8 Jahren.

Getting layout column width programatically

New Member Beiträge: 5 Beitrittsdatum: 03.05.15 Neueste Beiträge
Is there a programmatic way to obtain column width (in pixels or in the fraction of 12) from the currently active layout? I would prefer the Java API way. It is possible to do it with Javascript like taking X from the spanX class of the div with appropriate portlet-column class, but in a year or so there may be a different CSS and also that would not be a correct MVC approach.

I searched both forums and API but only found some ExpandoColumn classes which do not have such a method.

Thank you in advance.
thumbnail
Punam Shah, geändert vor 8 Jahren.

RE: Getting layout column width programatically

Regular Member Beiträge: 117 Beitrittsdatum: 20.01.12 Neueste Beiträge
To get column width using Java api.. Is not possible. As resolution keep change for each browser n each desktop, laptops.hence widht of the column will calculated on page loading time. You can get the information about type of columns and their respective portlets from layout.typesettings.
Martin Pasko, geändert vor 8 Jahren.

RE: Getting layout column width programatically

New Member Beiträge: 5 Beitrittsdatum: 03.05.15 Neueste Beiträge
Thank you for pointing me out. I found following way how to get to layout-template-id, which contains in its name also the column distribution:

ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
Layout layout = themeDisplay.getLayout();
layout.getTypeSettingsProperties().getProperty("layout-template-id");


I guess it would be possible to parse the name and count the columns programatically, however, there is no way to tell the percentual width of each column, as there are 12 possible width distributions. Here is just one example. Following two columns are distributed in a ratio 2/3 to 1/3.

<div class="portlet-column portlet-column-last span4" id="column-3"></div>


Since this depends on the template file used, the only way to determine the percentual width distribution is to parse the template file? I guess I will have to use JS then. It is so easy to overflow the container with absolute positionings etc.
thumbnail
Punam Shah, geändert vor 8 Jahren.

RE: Getting layout column width programatically

Regular Member Beiträge: 117 Beitrittsdatum: 20.01.12 Neueste Beiträge
Yes. JS will help you to get exact width. If you want get template content, you can try below :

String layoutTypeId = layout.getTypeSettingsProperties().getProperty("layout-template-id");
String layoutContent = LayoutTemplateLocalServiceUtil.getContent(layoutTypeId, false, theme.getThemeId());