Dynamic region name in layout view


#1

Hi,

I am trying to create a grid layout with a number of named regions. In my thymeleaf view file I’d like to iterate over these regions like this:

  <div data-th-each="region : ${regions}" data-th-remove="tag">
    <div data-portal-region="${region.name}">
      <div data-th-each="component : ${region.components}" data-th-remove="tag">
        <div data-portal-component="${component.path}" data-th-remove="tag"/>
      </div>
    </div>
  </div>

The regions are provided as an array to the view upon rendering. However, it seems that the ${region.name} in the data-portal-region attribute is not evaluated as code, and appears in the rendered html view as a string:

<div data-portal-region="${region.name}" class="ui-sortable"></div>

Clearly this prevents my layout from working properly in edit mode.

Why is the ${region.name} not evaluated as expected when applying it to data-portal-region name? When printing it as text it prints the correct region name.
Are there any nice tricks for programmatically setting region names?


#2

Hi Ingunn,

data-portal-region is a XP-specific attribute that is not parsed by the Thymeleaf-engine, it can only be a string. So it is not possible to create regions programmatically with XP (unless someone out there have done some experimental things?).


#3

As you may have seen, regions must be defined in your layout.xml file - this is for the data model to actually work regardless of how you might visualize your front-end. The purpose of this data-portal-region attribute is to enable the page editor to visually identify the region within the rendered html.